-
Notifications
You must be signed in to change notification settings - Fork 35
⚡ Bolt: Combine multiple aggregate queries in utility.py #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,20 +53,18 @@ def get_stats(db: Session = Depends(get_db)): | |
| if cached_stats: | ||
| return JSONResponse(content=cached_stats) | ||
|
|
||
| # Optimized: Single aggregate query to calculate total and resolved issues | ||
| stats = db.query( | ||
| # Optimized: Single aggregate query to calculate totals, resolved counts, and category distribution | ||
| cat_stats = db.query( | ||
| Issue.category, | ||
| func.count(Issue.id).label("total"), | ||
| func.sum(case((Issue.status.in_(['resolved', 'verified']), 1), else_=0)).label("resolved") | ||
| ).first() | ||
| ).group_by(Issue.category).all() | ||
|
|
||
| total = stats.total or 0 | ||
| resolved = int(stats.resolved or 0) | ||
| # Pending is everything else | ||
| total = sum(row.total for row in cat_stats) if cat_stats else 0 | ||
| resolved = int(sum(row.resolved or 0 for row in cat_stats)) if cat_stats else 0 | ||
| pending = total - resolved | ||
|
|
||
| # By category | ||
| cat_counts = db.query(Issue.category, func.count(Issue.id)).group_by(Issue.category).all() | ||
| issues_by_category = {cat: count for cat, count in cat_counts} | ||
| issues_by_category = {row.category: row.total for row in cat_stats} | ||
|
Comment on lines
+56
to
+67
|
||
|
|
||
| response = StatsResponse( | ||
| total_issues=total, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions verifying this change via
test_stats_endpoint.pyand says an isolated integration test was added, but there is no such test file underbackend/tests/in this PR. Either add the referenced test (recommended) or update the PR description/measurement instructions to point at an existing test path so reviewers can reproduce the claimed improvement.