Skip to content

⚡ Bolt: [performance improvement] Consolidate closure status queries#556

Open
RohanExploit wants to merge 2 commits intomainfrom
bolt-optimize-closure-status-queries-7200736870002847135
Open

⚡ Bolt: [performance improvement] Consolidate closure status queries#556
RohanExploit wants to merge 2 commits intomainfrom
bolt-optimize-closure-status-queries-7200736870002847135

Conversation

@RohanExploit
Copy link
Owner

@RohanExploit RohanExploit commented Mar 17, 2026

💡 What:
Replaced two separate COUNT queries on the ClosureConfirmation table with a single GROUP BY query in the get_closure_status endpoint (backend/routers/grievances.py).

🎯 Why:
The previous implementation performed three sequential database queries to compute the closure status variables: one for total followers, one for confirmed closures, and one for disputed closures. Combining the two confirmation type queries into one GROUP BY reduces database round-trips.

📊 Impact:
Reduces the number of database queries required to load the closure status from 3 to 2, mitigating potential N+1 or high latency issues on heavily-followed grievances and decreasing database load.

🔬 Measurement:
The performance improvement can be measured by tracing database calls during a GET /grievances/{id}/closure-status request; only 2 queries will be executed instead of 3.


PR created automatically by Jules for task 7200736870002847135 started by @RohanExploit


Summary by cubic

Consolidated closure status queries in get_closure_status to reduce database calls. Replaced two separate COUNT queries on ClosureConfirmation with a single GROUP BY on confirmation_type, bringing total queries from 3 to 2 and lowering latency for heavily followed grievances.

Written for commit 3102912. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Optimized database query performance in the grievances module by consolidating multiple separate count operations into a single aggregated query, reducing the number of database calls required.

Consolidates the separate `count` queries in the `get_closure_status` endpoint
into a single `group_by` query over `ClosureConfirmation.confirmation_type`.
This reduces the number of database queries executed during closure status retrieval.
Copilot AI review requested due to automatic review settings March 17, 2026 14:05
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@netlify
Copy link

netlify bot commented Mar 17, 2026

👷 Deploy Preview for fixmybharat processing.

Name Link
🔨 Latest commit 3102912
🔍 Latest deploy log https://app.netlify.com/projects/fixmybharat/deploys/69b96482d1aadd0008788cee

@github-actions
Copy link

🙏 Thank you for your contribution, @RohanExploit!

PR Details:

Quality Checklist:
Please ensure your PR meets the following criteria:

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Code is commented where necessary
  • Documentation updated (if applicable)
  • No new warnings generated
  • Tests added/updated (if applicable)
  • All tests passing locally
  • No breaking changes to existing functionality

Review Process:

  1. Automated checks will run on your code
  2. A maintainer will review your changes
  3. Address any requested changes promptly
  4. Once approved, your PR will be merged! 🎉

Note: The maintainers will monitor code quality and ensure the overall project flow isn't broken.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Consolidates two separate database count queries for ClosureConfirmation records into a single grouped aggregation query that returns counts per confirmation type. The endpoint then constructs confirmations_count and disputes_count from the aggregated results, reducing database round-trips while preserving existing functionality.

Changes

Cohort / File(s) Summary
Database Query Consolidation
backend/routers/grievances.py
Replaces two scalar count queries with a single grouped aggregation that counts ClosureConfirmation records by confirmation_type, then unpacks the results into separate count variables.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size/s, medium

Poem

🐰 One query hops where two once stood,
Grouped and swift, efficient as it should,
Fewer round-trips through the warren deep,
More data gathered in a single leap!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: consolidating closure status queries for performance improvement, matching the PR's primary objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering what was changed, why it was changed, and the measurable impact.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-optimize-closure-status-queries-7200736870002847135
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the performance of the GET /grievances/{id}/closure-status endpoint by reducing database round-trips when computing closure confirmation counts, replacing multiple COUNT queries on closure_confirmations with a single GROUP BY aggregation.

Changes:

  • Consolidated confirmed/disputed closure counts into one GROUP BY query.
  • Converted grouped results into a dictionary to preserve the existing response fields (confirmations_count, disputes_count).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Consolidates the separate `count` queries in the `get_closure_status` endpoint
into a single `group_by` query over `ClosureConfirmation.confirmation_type`.
This reduces the number of database queries executed during closure status retrieval.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants