perf: bound public activity aggregation

This commit is contained in:
ik
2026-09-22 20:17:55 +07:00
parent a501b5ea9d
commit 1da9279ddf
5 changed files with 29 additions and 13 deletions
+2
View File
@@ -14,6 +14,7 @@ from ..schemas import TackleCombinationOut
router = APIRouter()
FRESHNESS_HALF_LIFE_HOURS = 12.5
MAX_ANALYTICS_FACTS = 10_000
def _age_hours(value: datetime, now: datetime) -> float:
@@ -53,6 +54,7 @@ def tackle_combinations(
query = query.join(Fish, CatchReport.fish_id == Fish.id).where(Fish.slug == fish)
if method:
query = query.where(CatchReport.fishing_method == method)
query = query.order_by(CatchReport.caught_at.desc(), CatchReport.reported_at.desc(), CatchReport.id.desc()).limit(MAX_ANALYTICS_FACTS)
groups: dict[tuple[str, str], list[CatchReport]] = defaultdict(list)
for report in db.scalars(query):