-
Notifications
You must be signed in to change notification settings - Fork 38
⚡ Bolt: Bounding box pre-filter for spatial issue queries #900
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||
| import json | ||||||
| import os | ||||||
| import io | ||||||
| import sys | ||||||
|
|
||||||
| # Add the project root to sys.path so we can import 'backend' modules | ||||||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||||||
|
|
@@ -234,26 +235,11 @@ async def create_issue( | |||||
|
|
||||||
| # Offload blocking file I/O to a thread | ||||||
| def save_file(): | ||||||
| with open(image_path, "wb") as buffer: | ||||||
| with open(file_location, "wb") as buffer: | ||||||
| shutil.copyfileobj(image.file, buffer) | ||||||
|
|
||||||
| await asyncio.to_thread(save_file) | ||||||
|
|
||||||
| # Offload blocking DB operations to a thread | ||||||
| def save_to_db(): | ||||||
| new_issue = Issue( | ||||||
| description=description, | ||||||
| category=category, | ||||||
| image_path=image_path, | ||||||
| source="web" | ||||||
| ) | ||||||
| db.add(new_issue) | ||||||
| db.commit() | ||||||
| db.refresh(new_issue) | ||||||
| return new_issue | ||||||
|
|
||||||
| new_issue = await asyncio.to_thread(save_to_db) | ||||||
|
|
||||||
| # Generate Action Plan (AI) | ||||||
| action_plan = await generate_action_plan(description, category, file_location) | ||||||
|
|
||||||
|
|
@@ -268,11 +254,14 @@ def save_to_db(): | |||||
| db.commit() | ||||||
| db.refresh(db_issue) | ||||||
|
|
||||||
| return { | ||||||
| "id": new_issue.id, | ||||||
| "message": "Issue reported successfully", | ||||||
| "action_plan": action_plan | ||||||
| } | ||||||
| return { | ||||||
| "id": db_issue.id, | ||||||
| "message": "Issue reported successfully", | ||||||
| "action_plan": action_plan | ||||||
| } | ||||||
| except Exception as e: | ||||||
| logger.error(f"Error creating issue: {e}", exc_info=True) | ||||||
| raise HTTPException(status_code=500, detail=str(e)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Upload failures expose raw internal exception text to clients. Log the exception server-side and return a stable generic error detail instead. Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| @lru_cache(maxsize=1) | ||||||
| def _load_responsibility_map(): | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,10 +76,22 @@ def find_nearby_issues( | |
| """ | ||
| nearby_issues = [] | ||
|
|
||
| # Bolt Optimization: Fast bounding box pre-filter | ||
| # Use a bounding box to quickly exclude issues far outside the radius | ||
| # before calculating the expensive Haversine distance. We add a small | ||
| # 5% epsilon to the radius to prevent missing edge cases due to projection differences. | ||
| eps = radius_meters * 0.05 | ||
| min_lat, max_lat, min_lon, max_lon = get_bounding_box(target_lat, target_lon, radius_meters + eps) | ||
|
|
||
| for issue in issues: | ||
| if issue.latitude is None or issue.longitude is None: | ||
| continue | ||
|
|
||
| # Skip Haversine if clearly outside the bounding box | ||
| if (issue.latitude < min_lat or issue.latitude > max_lat or | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The bounding box pre-filter doesn't handle longitude wrapping at the international date line (±180°). When the target is near ±180° and the radius is large enough that the bounding box spans across the date line, the simple Prompt for AI agents |
||
| issue.longitude < min_lon or issue.longitude > max_lon): | ||
| continue | ||
|
Comment on lines
+90
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Search for any geographic scope restrictions or antimeridian handling in the codebase.
rg -nP --type=py -C2 'longitude|antimeridian|dateline|180' backend/ --glob '!**/spatial_utils.py' | head -40Repository: RohanExploit/VishwaGuru Length of output: 2533 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== spatial_utils.py =="
ast-grep outline backend/spatial_utils.py --view expanded || true
echo
echo "== Search for geographic scope / region restrictions =="
rg -nP --type=py -C2 'India|Maharashtra|country|state|region|bounded|latitude|longitude|antimeridian|dateline|180' backend/ frontend/ . --glob '!**/spatial_utils.py' | head -200
echo
echo "== Files mentioning spatial queries or bounding boxes =="
rg -n --glob '*.py' 'get_bounding_box|haversine_distance|bounding box|spatial' backend | head -200Repository: RohanExploit/VishwaGuru Length of output: 15270 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== backend/spatial_utils.py (relevant section) =="
sed -n '1,130p' backend/spatial_utils.py | cat -n
echo
echo "== Search for coordinate validation / geocoding restrictions =="
rg -n --glob '*.py' 'ge=-180|le=180|ge=-90|le=90|Maharashtra|India|country|state|district|city|longitude|latitude' backend | head -300Repository: RohanExploit/VishwaGuru Length of output: 23827 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== find_nearby_issues call sites =="
rg -n --glob '*.py' 'find_nearby_issues\(' backend | cat
echo
echo "== get_bounding_box implementation call context =="
rg -n -C3 --glob '*.py' 'get_bounding_box\(' backend/spatial_utils.py backend | catRepository: RohanExploit/VishwaGuru Length of output: 2390 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== backend/spatial_utils.py (lines 1-130) =="
sed -n '1,130p' backend/spatial_utils.py | cat -n
echo
echo "== find_nearby_issues call sites =="
rg -n --glob '*.py' 'find_nearby_issues\(' backend | catRepository: RohanExploit/VishwaGuru Length of output: 5299 Handle antimeridian wrap in the bounding-box prefilter. 🤖 Prompt for AI Agents |
||
|
|
||
| distance = haversine_distance( | ||
| target_lat, target_lon, | ||
| issue.latitude, issue.longitude | ||
|
|
||
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.
P2: Failed issue uploads now hit a
NameErrorwhile handling the original exception becauseloggeris undefined. Define the module logger (and importlogging) or remove this logging call so this handler reliably returns its 500 response.Prompt for AI agents