blob: 5018b326b69a65cc96a4979fc64450d8b64bde0e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
from __future__ import annotations
from datetime import UTC, datetime, timedelta
from sqlalchemy import delete
from sqlalchemy.orm import Session
from srht_contrib.models import ContributionEvent
RETENTION_DAYS = 365
def prune_contribution_events(db: Session, *, now: datetime | None = None) -> int:
cutoff = (now or datetime.now(tz=UTC)) - timedelta(days=RETENTION_DAYS)
result = db.execute(delete(ContributionEvent).where(ContributionEvent.occurred_at < cutoff))
return int(result.rowcount or 0)
|