auto-sync: 2026-05-04 11:30:01

This commit is contained in:
Stream
2026-05-04 11:30:01 +03:00
parent d1e0267184
commit 8ebc01ea2b

View File

@@ -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)