Skip to content

perf: eliminate N+1 queries on queues index#77

Merged
eclectic-coding merged 2 commits into
mainfrom
feat/eliminate-n-plus-one-queries
May 28, 2026
Merged

perf: eliminate N+1 queries on queues index#77
eclectic-coding merged 2 commits into
mainfrom
feat/eliminate-n-plus-one-queries

Conversation

@eclectic-coding
Copy link
Copy Markdown
Owner

Summary

  • queue.size previously called ReadyExecution.queued_as(name).count — one COUNT query per queue
  • queue.paused? previously called Pause.exists?(queue_name: name) — one EXISTS query per queue
  • Both are now pre-computed in QueuesController#index with two batch queries: a single GROUP BY queue_name aggregation for sizes and one Pause.pluck(:queue_name) for paused state
  • View reads from @queue_sizes[queue.name] and @paused_queue_names.include?(queue.name) instead
  • Query count reduced from O(2N + constant) to O(constant) regardless of queue count

Test plan

  • 6 new specs: correct size display (with and without ready jobs), Paused/Running badge, Resume/Pause button rendering
  • All existing pause/resume action specs still pass
  • Full suite green: 357 examples, 0 failures, 100% line coverage

Closes #76

🤖 Generated with Claude Code

eclectic-coding and others added 2 commits May 28, 2026 06:39
Replace per-queue queue.size (COUNT) and queue.paused? (EXISTS) calls with
two batch aggregations pre-computed in QueuesController#index: a single
GROUP BY query for ready execution counts and one Pause.pluck for paused
state. Reduces query count from O(2N + constant) to O(constant) regardless
of the number of queues. View updated to read from the pre-computed hashes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@eclectic-coding eclectic-coding merged commit db29d95 into main May 28, 2026
5 checks passed
@eclectic-coding eclectic-coding deleted the feat/eliminate-n-plus-one-queries branch May 28, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: eliminate N+1 queries on queues index

1 participant