diff --git a/.jules/bolt.md b/.jules/bolt.md index 6f687f0a..0e2d6524 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -37,3 +37,7 @@ ## 2026-02-08 - Return Type Consistency in Utilities **Learning:** Inconsistent return types in shared utility functions (like `process_uploaded_image`) can cause runtime crashes across multiple modules, especially when some expect tuples and others expect single values. This can lead to deployment failures that are hard to debug without full integration logs. **Action:** Always maintain strict return type consistency for core utilities. Use type hints and verify all call sites when changing a function's signature. Ensure that performance-oriented optimizations (like returning multiple processed formats) are applied uniformly. + +## 2026-05-24 - Unbounded Spatial Queries +**Learning:** Spatial bounding box queries without a `LIMIT` clause can cause severe performance degradation in dense areas or when using large search radii. The application attempts to load and process all matching records in Python, leading to O(N) memory usage and processing time. +**Action:** Always apply a safety `.limit()` to spatial candidate queries to prevent worst-case scenarios, even if the primary filter is a bounding box. A reasonable limit (e.g., 100) balances result completeness with system stability. diff --git a/backend/routers/issues.py b/backend/routers/issues.py index 2ad27ca3..4b2cd5fa 100644 --- a/backend/routers/issues.py +++ b/backend/routers/issues.py @@ -98,6 +98,7 @@ async def create_issue( min_lat, max_lat, min_lon, max_lon = get_bounding_box(latitude, longitude, 50.0) # Performance Boost: Use column projection to avoid loading full model instances + # Optimization: Limit to 100 to prevent loading too many issues in dense areas open_issues = await run_in_threadpool( lambda: db.query( Issue.id, @@ -114,7 +115,7 @@ async def create_issue( Issue.latitude <= max_lat, Issue.longitude >= min_lon, Issue.longitude <= max_lon - ).all() + ).limit(100).all() ) nearby_issues_with_distance = find_nearby_issues( @@ -307,6 +308,7 @@ def get_nearby_issues( min_lat, max_lat, min_lon, max_lon = get_bounding_box(latitude, longitude, radius) # Performance Boost: Use column projection to avoid loading full model instances + # Optimization: Limit to 100 to prevent loading too many issues in dense areas open_issues = db.query( Issue.id, Issue.description, @@ -322,7 +324,7 @@ def get_nearby_issues( Issue.latitude <= max_lat, Issue.longitude >= min_lon, Issue.longitude <= max_lon - ).all() + ).limit(100).all() nearby_issues_with_distance = find_nearby_issues( open_issues, latitude, longitude, radius_meters=radius diff --git a/render.yaml b/render.yaml index 593ec813..60a7e050 100644 --- a/render.yaml +++ b/render.yaml @@ -14,7 +14,7 @@ services: name: vishwaguru-backend property: port - key: PYTHONPATH - value: backend + value: . # Required API Keys (must be set in Render dashboard) - key: GEMINI_API_KEY sync: false