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