A client came to us with a fleet dashboard that took nine seconds to render. Their assumption — a reasonable one — was that they had outgrown their database server. They had not. The server was close to idle while the page loaded.
Measure before you touch anything
We installed a query profiler and loaded the page once. It issued just over four thousand queries. Twelve of them were the report; the rest were an N+1 on the vehicle relation, nested inside a second N+1 on the driver relation. Eager loading both cut the page to two and a half seconds before we changed a single line of business logic.
The remaining time was one report
What was left was a utilisation report that aggregated eighteen months of trip records on every page load, for a figure that changes once a day. We moved it to a scheduled job that writes a single summary row, and the dashboard now reads that row. Page load landed at 780 milliseconds on the same hardware.
The lesson is not about queries
The client had already priced a server upgrade. It would have bought them perhaps thirty percent, at a recurring cost, and left the N+1 in place to be rediscovered at the next growth step. Profiling first cost half a day and cost them nothing in infrastructure.
Tagged
Comments
Sign in to join the discussion.