Skip to content

fix: batch story item counts in list_stories to eliminate N+1#663

Open
neuron-tech-ai wants to merge 1 commit into
jamiepine:mainfrom
neuron-tech-ai:fix/story-list-n-plus-one
Open

fix: batch story item counts in list_stories to eliminate N+1#663
neuron-tech-ai wants to merge 1 commit into
jamiepine:mainfrom
neuron-tech-ai:fix/story-list-n-plus-one

Conversation

@neuron-tech-ai
Copy link
Copy Markdown

list_stories was issuing one COUNT query per story to get item counts — O(n) database queries for a page of n stories. On large libraries this caused noticeable latency on every page load of the stories list.

Replaced with a single GROUP BY query that fetches all counts in one round trip. Straightforward fix, meaningful speedup at scale.

list_stories() previously executed one COUNT(story_items) query per
story in a Python loop. With N stories that is N+1 round-trips to
SQLite regardless of list length. Replace with a single aggregated
GROUP BY query that fetches all counts at once, then populate each
StoryResponse from a dict lookup.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@neuron-tech-ai has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0682ff44-becb-4491-93f0-fd6d2a712af2

📥 Commits

Reviewing files that changed from the base of the PR and between b35b909 and ac0e1e4.

📒 Files selected for processing (1)
  • backend/services/stories.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant