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
+4
View File
@@ -10,6 +10,8 @@ from sqlalchemy.orm import Session, joinedload
from .models import CatchReport, ModerationStatus
from .schemas import ActivityOut
MAX_ACTIVITY_FACTS = 10_000
def activity_rows(
session: Session,
@@ -33,6 +35,8 @@ def activity_rows(
CatchReport.spot_id.is_not(None),
CatchReport.reported_at >= now - timedelta(hours=hours),
)
.order_by(CatchReport.reported_at.desc(), CatchReport.id.desc())
.limit(MAX_ACTIVITY_FACTS)
)
if waterbody:
query = query.where(CatchReport.waterbody.has(slug=waterbody))