Fix sync window: respect lookback_days even after first sync
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user