Add configurable sync_lookback_days for Garmin Connect
Build and push images / validate (push) Successful in 2s
Build and push images / build-backend (push) Successful in 7s
Build and push images / build-worker (push) Successful in 6s
Build and push images / build-frontend (push) Successful in 10s

Users can now set how many days back the first sync fetches. -1 syncs all
history back to 2010; any positive value sets a rolling window. Values
over 365 show a rate-limit warning in the UI. The default remains 30 days.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 00:40:55 +01:00
parent 335bd0a053
commit f8c126fbda
4 changed files with 31 additions and 10 deletions
+9 -4
View File
@@ -67,12 +67,13 @@ def authenticate_garmin(email: str, password_enc: str, token_store: Optional[str
# ── Activity sync ─────────────────────────────────────────────────────────────
def sync_activities(garmin, user_id: int, since: Optional[datetime],
db, file_store_path: str) -> int:
db, file_store_path: str, lookback_days: int = 30) -> int:
"""
List activities from Garmin Connect, skip any already in the DB, download
FIT ZIPs for new ones, and queue them for processing.
On first sync (since=None) fetches the full account history back to 2010.
On first sync (since=None) the start date is determined by lookback_days:
-1 → full history back to 2010; N → today minus N days.
On incremental syncs fetches from one day before last_sync_at.
Returns the number of new activities queued.
"""
@@ -81,8 +82,12 @@ def sync_activities(garmin, user_id: int, since: Optional[datetime],
from app.models.user import Activity
from sqlalchemy import select, func
# First sync: fetch everything; incremental: one day overlap to catch late uploads
start_date = (since - timedelta(days=1)).date() if since else date(2010, 1, 1)
if since:
start_date = (since - timedelta(days=1)).date()
elif lookback_days == -1:
start_date = date(2010, 1, 1)
else:
start_date = date.today() - timedelta(days=max(lookback_days, 1))
end_date = date.today()
try: