Fix sync window: respect lookback_days even after first sync
Build and push images / validate (push) Successful in 2s
Build and push images / build-backend (push) Successful in 6s
Build and push images / build-worker (push) Successful in 5s
Build and push images / build-frontend (push) Successful in 6s

Previously, once last_sync_at was set the incremental path always used
since-1d as start_date, ignoring lookback_days entirely. Increasing the
lookback setting had no effect on already-synced instances.

Fix: take min(since-1d, today-lookback_days) so the window always covers
at least the configured lookback period, whether or not a prior sync ran.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 11:16:08 +01:00
parent 616099402b
commit f0bbe92b2c
+10 -4
View File
@@ -91,8 +91,11 @@ def sync_activities(garmin, user_id: int, since: Optional[datetime],
# All-time: full pull on first sync, incremental thereafter
start_date = (since - timedelta(days=1)).date() if since else date(2010, 1, 1)
elif since:
# Incremental: one day overlap to catch any late-arriving activities
start_date = (since - timedelta(days=1)).date()
# Use whichever is earlier: one day before last sync OR the configured lookback
# window. This ensures increasing lookback_days actually fetches older data.
incremental = (since - timedelta(days=1)).date()
lookback = date.today() - timedelta(days=max(lookback_days, 1))
start_date = min(incremental, lookback)
else:
start_date = date.today() - timedelta(days=max(lookback_days, 1))
end_date = date.today()
@@ -194,8 +197,11 @@ def sync_wellness(garmin, user_id: int, since: Optional[datetime], db,
if lookback_days == -1:
start_date = (since - timedelta(days=1)).date() if since else date(2010, 1, 1)
elif since:
# Incremental: one day overlap to catch any late-arriving wellness data
start_date = (since - timedelta(days=1)).date()
# Use whichever is earlier: one day before last sync OR the configured lookback
# window. This ensures increasing lookback_days actually fetches older data.
incremental = (since - timedelta(days=1)).date()
lookback = date.today() - timedelta(days=max(lookback_days, 1))
start_date = min(incremental, lookback)
else:
start_date = date.today() - timedelta(days=max(lookback_days, 1))
days = (date.today() - start_date).days + 1