Skip to content

Fix benchmark files: remove unused imports, fix Grievance seed data, move DB setup out of module scope#561

Merged
RohanExploit merged 2 commits intobolt-optimize-closure-count-queries-6106104410388610831from
copilot/sub-pr-558
Mar 19, 2026
Merged

Fix benchmark files: remove unused imports, fix Grievance seed data, move DB setup out of module scope#561
RohanExploit merged 2 commits intobolt-optimize-closure-count-queries-6106104410388610831from
copilot/sub-pr-558

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Addresses four reviewer findings in the benchmark scripts added by the GROUP BY optimization PR.

Changes

backend/tests/benchmark_closure_status.py

  • Removed unused imports: get_db, ClosureService, patch, MagicMock, sys, os
  • Removed sys.path.insert(0, os.path.abspath('.')) — unnecessary when running via python -m
  • Fixed seed_data() to satisfy all non-null FK constraints: creates a Jurisdiction row first, then populates Grievance.severity, current_jurisdiction_id, assigned_authority, and sla_deadline

backend/tests/test_closure_status_benchmark.py

  • Removed unused sys and os imports
  • Moved create_engine, create_all, and sessionmaker setup inside run_benchmark() — previously at module scope, causing DB creation as a side effect during pytest collection
# Before: executed at import time
engine = create_engine('sqlite:///:memory:', ...)
Base.metadata.create_all(bind=engine)

# After: scoped to the benchmark function
def run_benchmark():
    engine = create_engine('sqlite:///:memory:', ...)
    Base.metadata.create_all(bind=engine)
    TestingSessionLocal = sessionmaker(..., bind=engine)

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Code style update (formatting, renaming)
  • ♻️ Refactoring (no functional changes)
  • ⚡ Performance improvement
  • ✅ Test update

Related Issue

Closes #

Testing Done

  • Tested locally
  • Added/updated tests
  • All tests passing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Co-Authors


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.


Summary by cubic

Optimize closure status queries by aggregating results with SQL GROUP BY. Speeds up closure count views and updates benchmarks to seed valid data and avoid module-level DB side effects.

  • Performance

    • Consolidates multiple COUNTs into one grouped query.
    • Fewer DB round-trips; lower CPU on list/dashboard views.
    • No change to API responses or data shape.
  • Bug Fixes

    • Removed unused imports and mocks in benchmark tests.
    • Seeded Jurisdiction and required Grievance fields (severity, current_jurisdiction_id, assigned_authority, sla_deadline).
    • Moved SQLite setup into run_benchmark() to prevent pytest collection side effects.

Written for commit 62206ab. Summary will update on new commits.

…data, move DB setup out of module level

Co-authored-by: RohanExploit <178623867+RohanExploit@users.noreply.github.com>
Copilot AI changed the title [WIP] [6106104410388610831] Optimize closure status queries using GROUP BY Fix benchmark files: remove unused imports, fix Grievance seed data, move DB setup out of module scope Mar 19, 2026
Copilot AI requested a review from RohanExploit March 19, 2026 10:38
@RohanExploit RohanExploit marked this pull request as ready for review March 19, 2026 10:39
Copilot AI review requested due to automatic review settings March 19, 2026 10:39
@RohanExploit RohanExploit merged commit f7abfcc into bolt-optimize-closure-count-queries-6106104410388610831 Mar 19, 2026
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 cleans up and fixes the closure-status benchmark scripts introduced alongside the GROUP BY optimization work, ensuring benchmarks seed valid data and avoid unintended side effects during pytest collection.

Changes:

  • Removes unused imports and unneeded path manipulation in the closure-status benchmark scripts.
  • Fixes seed_data() in the closure-status benchmark to satisfy Grievance/FK non-null constraints by creating a Jurisdiction and setting required fields.
  • Moves in-memory SQLite setup in test_closure_status_benchmark.py into run_benchmark() to prevent DB creation at import time.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
backend/tests/test_closure_status_benchmark.py Moves SQLite engine/table setup into run_benchmark() and removes unused imports to avoid pytest collection side effects.
backend/tests/benchmark_closure_status.py Updates benchmark seeding to create valid Jurisdiction/Grievance rows and removes unused imports/path hacks.

💡 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.

Comment on lines +33 to 35
assigned_authority="Municipal Corporation",
sla_deadline=datetime.utcnow() + timedelta(hours=72),
pincode="123456",
Comment on lines +2 to 6
from datetime import datetime, timedelta

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

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 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants