perf: bound public activity aggregation
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user