A query fast enough to never appear in a slow log, accounting for a fifth of all database time.
calls: 4,128,840 a month
per call: 2.1ms
total: 2.4 hours of database time
what it is: a settings lookup, by key, in a
middleware, on every request
what it should be: one query per request for all
keys, or a cached array.
after: one query per request, 41ms saved per request
for requests that read more than one setting.
A slow query log has a threshold and a query below it is invisible regardless of how often it runs, which is why the aggregation across all queries matters more than the slow log. The fix was not making the query faster — it was making it happen once instead of twenty times, which is a call-site problem rather than a database one.