From 61849761747da4fca0d5ff749ae1dae13dedb5b9 Mon Sep 17 00:00:00 2001 From: Stream Date: Sun, 3 May 2026 10:34:58 +0000 Subject: [PATCH] perf(tiles): filter trails by length_m per zoom level - z<=7: min 2000m, limit 3000 - z==8: min 500m, limit 8000 - z==9: min 200m, limit 8000 - z==10: min 50m, limit 15000 - z>=11: no filter, limit 25000 Reduces row count from 25k to ~hundreds on z8 tiles. --- tasks/enduro-trails/prototype/app.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tasks/enduro-trails/prototype/app.py b/tasks/enduro-trails/prototype/app.py index 614506b..4a97680 100644 --- a/tasks/enduro-trails/prototype/app.py +++ b/tasks/enduro-trails/prototype/app.py @@ -252,14 +252,26 @@ async def get_tile(z: int, x: int, y: int): q_north = north + buf_y if z <= 7: - limit = 5000 + limit = 3000 elif z <= 9: - limit = 25000 + limit = 8000 elif z <= 11: - limit = 25000 + limit = 15000 else: limit = 25000 + # Минимальная длина трека по зуму — фильтруем мусор на низких зумах + if z <= 7: + min_length = 2000 + elif z == 8: + min_length = 500 + elif z == 9: + min_length = 200 + elif z == 10: + min_length = 50 + else: + min_length = 0 + try: conn = get_db() cur = conn.cursor() @@ -269,8 +281,9 @@ async def get_tile(z: int, x: int, y: int): FROM trails WHERE min_lon <= ? AND max_lon >= ? AND min_lat <= ? AND max_lat >= ? + AND (length_m >= ? OR length_m IS NULL) LIMIT ? - """, (q_east, q_west, q_north, q_south, limit)) + """, (q_east, q_west, q_north, q_south, min_length, limit)) trails_rows = cur.fetchall() cur.execute("""