From 8ebc01ea2b26de2e611b0ccf27d9ec6e14ebe6dc Mon Sep 17 00:00:00 2001 From: Stream Date: Mon, 4 May 2026 11:30:01 +0300 Subject: [PATCH] auto-sync: 2026-05-04 11:30:01 --- tasks/enduro-trails/prototype/app.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tasks/enduro-trails/prototype/app.py b/tasks/enduro-trails/prototype/app.py index c390236..fde7041 100644 --- a/tasks/enduro-trails/prototype/app.py +++ b/tasks/enduro-trails/prototype/app.py @@ -282,28 +282,43 @@ def calc_route_stats(geometry: dict, conn) -> dict | None: if grid_key in grid_cache: hw, tt = grid_cache[grid_key] else: - # Bbox ~300м вокруг точки - delta = 0.003 + # Tight bbox ~150m — index on (min_lon, max_lon, min_lat, max_lat) is used + # No ORDER BY to avoid full scan; first bbox hit is good enough for stats + delta = 0.0015 try: cur.execute(""" SELECT highway_type, track_type FROM trails WHERE min_lon <= ? AND max_lon >= ? AND min_lat <= ? AND max_lat >= ? - ORDER BY ABS((min_lon + max_lon) / 2.0 - ?) + - ABS((min_lat + max_lat) / 2.0 - ?) LIMIT 1 """, ( mid_lon + delta, mid_lon - delta, mid_lat + delta, mid_lat - delta, - mid_lon, mid_lat )) row = cur.fetchone() if row: hw = (row["highway_type"] or "").lower() tt = (row["track_type"] or "").lower() else: - hw, tt = "asphalt", "" + # Widen search to ~500m if nothing found nearby + delta2 = 0.005 + cur.execute(""" + SELECT highway_type, track_type + FROM trails + WHERE min_lon <= ? AND max_lon >= ? + AND min_lat <= ? AND max_lat >= ? + LIMIT 1 + """, ( + mid_lon + delta2, mid_lon - delta2, + mid_lat + delta2, mid_lat - delta2, + )) + row = cur.fetchone() + if row: + hw = (row["highway_type"] or "").lower() + tt = (row["track_type"] or "").lower() + else: + hw, tt = "asphalt", "" except Exception: hw, tt = "asphalt", "" grid_cache[grid_key] = (hw, tt)