perf: eliminate N+1 queries across list views and add covering indexes#88
Merged
Conversation
Replace per-queue COUNT loop in QueuesController with a single GROUP BY aggregation; combine two separate pluck calls in JobsController into one; replace 5+1 COUNT queries in CacheSizeStats with a single SUM(CASE WHEN) aggregation and derive #total from bucket counts. Add covering indexes to the dummy schema for the slow-job scan and for queue_name lookups on scheduled and blocked execution tables. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #47
Summary
COUNTloop inQueuesController#indexwith a singleGROUP BY queue_nameaggregation — was O(N) queries, now always 2pluckcalls for queue/priority filter options inJobsController#indexinto one queryCOUNTqueries inCacheSizeStats#bucketswith a singleSUM(CASE WHEN ...)aggregation; derive#totalfrom the already-computed bucket countssolid_queue_jobs (finished_at, created_at)for the slow-job scan;(queue_name, created_at)onsolid_queue_scheduled_executionsandsolid_queue_blocked_executions(both previously lacked a queue-name index)Test plan
bundle exec rakepasses (325 examples, 0 failures, no Rubocop offenses)🤖 Generated with Claude Code