diff options
| author | Christian Cleberg <[email protected]> | 2026-04-11 13:58:01 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-11 13:58:01 -0500 |
| commit | 6149ca9c394df7d316f80db05ad0fc2aea6c550d (patch) | |
| tree | 11f6cebc445e14b4a79adae648eb46d4be710071 /src/srht_contrib/api/routes_contributions.py | |
| parent | b6d1348abf907b8b9c16ab87487eb9384dc4cc89 (diff) | |
| download | hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.tar.gz hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.tar.bz2 hutch-stats-6149ca9c394df7d316f80db05ad0fc2aea6c550d.zip | |
feat: add lazy actor indexing for contribution lookups
Diffstat (limited to 'src/srht_contrib/api/routes_contributions.py')
| -rw-r--r-- | src/srht_contrib/api/routes_contributions.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/srht_contrib/api/routes_contributions.py b/src/srht_contrib/api/routes_contributions.py index c682553..25bc3c2 100644 --- a/src/srht_contrib/api/routes_contributions.py +++ b/src/srht_contrib/api/routes_contributions.py @@ -41,12 +41,16 @@ def get_contributions( year: int | None = Query(default=None, ge=1970, le=3000), from_date: str | None = Query(default=None, alias="from"), to_date: str | None = Query(default=None, alias="to"), + poller: PollerService = Depends(get_poller), db: Session = Depends(get_db), actor_identity_resolver: ActorIdentityResolver = Depends(get_actor_identity_resolver), ) -> ContributionCalendarResponse: start, end = _resolve_range(year, from_date, to_date) canonical_actor = actor_identity_resolver.canonicalize(actor, db=db) - return ContributionAggregator().build_calendar(db, canonical_actor, start, end) + poller.track_actor_request(db, canonical_actor) + response = ContributionAggregator().build_calendar(db, canonical_actor, start, end) + db.commit() + return response @router.get("/{actor}/stats", response_model=ContributionStatsResponse) @@ -55,12 +59,16 @@ def get_contribution_stats( year: int | None = Query(default=None, ge=1970, le=3000), from_date: str | None = Query(default=None, alias="from"), to_date: str | None = Query(default=None, alias="to"), + poller: PollerService = Depends(get_poller), db: Session = Depends(get_db), actor_identity_resolver: ActorIdentityResolver = Depends(get_actor_identity_resolver), ) -> ContributionStatsResponse: start, end = _resolve_range(year, from_date, to_date) canonical_actor = actor_identity_resolver.canonicalize(actor, db=db) - return ContributionAggregator().build_stats(db, canonical_actor, start, end) + poller.track_actor_request(db, canonical_actor) + response = ContributionAggregator().build_stats(db, canonical_actor, start, end) + db.commit() + return response @router.post("/poll", response_model=PollResponse, dependencies=[Depends(require_api_key)]) |
