Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/civic_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def run_daily_cycle(self):

# 1. Fetch Data
# Get issues created in the last 24 hours
issues_24h = db.query(Issue).filter(Issue.created_at >= last_24h).all()
# Performance Optimization: Use column projection to avoid loading full ORM models,
# since trend analyzer only needs specific attributes (id, description, category, lat, lon, upvotes, created_at)
issues_24h = db.query(
Issue.id, Issue.description, Issue.category,
Issue.latitude, Issue.longitude, Issue.upvotes, Issue.created_at
).filter(Issue.created_at >= last_24h).all()

# 2. Trend Analysis
trends = trend_analyzer.analyze(issues_24h)
Expand Down
11 changes: 7 additions & 4 deletions backend/tests/test_civic_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,18 @@ def open_side_effect(file, mode='r', *args, **kwargs):

# Define query side effects
def query_side_effect(*args):
if len(args) == 1:
if len(args) > 0:
model = args[0]
if getattr(model, '__name__', '') == 'Issue':
# Handle column projection (InstrumentedAttribute) by checking class_
class_name = getattr(model, 'class_', model).__name__ if hasattr(model, 'class_') else getattr(model, '__name__', '')

if class_name == 'Issue':
return mock_query_issues
elif hasattr(model, 'name') and model.name == 'count':
return mock_query_issues
Comment on lines 154 to 163
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This test doesn’t currently assert that Session.query() is called with the projected Issue columns. Adding an assertion (and returning Row/KeyedTuple-like results for issues_24h) would protect the new optimization from regressions and better exercise the new input shape passed into the pipeline.

Copilot uses AI. Check for mistakes.
elif getattr(model, '__name__', '') == 'EscalationAudit':
elif class_name == 'EscalationAudit':
return mock_query_upgrades
elif getattr(model, '__name__', '') == 'Grievance':
elif class_name == 'Grievance':
return mock_query_grievance
return MagicMock()

Expand Down
Loading