aboutsummaryrefslogtreecommitdiff
path: root/web/sync.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-27 13:37:26 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-27 13:37:26 +0200
commitabbbf17bcfe6dfa663b7019c4892db09e27b3808 (patch)
tree483968e14d6e853aeb909724e7d60998f3d2a4b2 /web/sync.go
parent6ec883a7fd40a14f2882076bd1a377bbbd0438ad (diff)
Resync Strava title from list payload via Save
Context / Problem: Strava titles can be corrected after import. The sync path only handled new rides; existing rides were marked skipped without checking the cheap list metadata, so corrections like ride #789 stayed stale. What: In syncRides reuse the existing Save write path for rare title resyncs (pay GPX parse cost) when existing.Name != list.Name; track progress.Updated and surface it in SSE/TS UI; add tests for resync without stream fetch. Remove the now-obsolete TODO. QA: go test/ vet, tsc, biome/stylelint pass.
Diffstat (limited to 'web/sync.go')
-rw-r--r--web/sync.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/web/sync.go b/web/sync.go
index 0b95b93..f6dc7da 100644
--- a/web/sync.go
+++ b/web/sync.go
@@ -100,7 +100,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
return
}
enrichProgressRateLimit(&progress, client)
- slog.Info("Completed Strava sync", "from", from.Format(dateFormat), "to", to.Add(-24*time.Hour).Format(dateFormat), "total", progress.Total, "imported", progress.Imported, "skipped", progress.Skipped, "readDaily", rateLimitLogValue(progress.RateLimit, true), "overallDaily", rateLimitLogValue(progress.RateLimit, false))
+ slog.Info("Completed Strava sync", "from", from.Format(dateFormat), "to", to.Add(-24*time.Hour).Format(dateFormat), "total", progress.Total, "imported", progress.Imported, "skipped", progress.Skipped, "updated", progress.Updated, "readDaily", rateLimitLogValue(progress.RateLimit, true), "overallDaily", rateLimitLogValue(progress.RateLimit, false))
_ = writeSyncEvent(w, flusher, "complete", progress)
}
@@ -122,12 +122,24 @@ func (s *Server) syncRides(client syncClient, gpxDir string, from, to time.Time,
}
for _, summary := range activities {
externalID := fmt.Sprintf("strava:%d", summary.ID)
- _, exists, err := ride.GetByExternalID(s.db, externalID)
+ existing, exists, err := ride.GetByExternalID(s.db, externalID)
if err != nil {
return progress, err
}
if exists {
- progress.Skipped++
+ if existing.Name != summary.Name {
+ existing.Name = summary.Name
+ if err := ride.Save(s.db, existing); err != nil {
+ if reportErr := skipSyncActivity(&progress, report, summary, fmt.Errorf("resync metadata: %w", err)); reportErr != nil {
+ return progress, reportErr
+ }
+ continue
+ }
+ progress.Updated++
+ slog.Info("Resynced Strava ride metadata", "activity", summary.ID, "name", summary.Name)
+ } else {
+ progress.Skipped++
+ }
progress.Completed++
if err := reportSyncProgress(report, progress); err != nil {
return progress, err
@@ -297,7 +309,7 @@ func rateLimitMessage(rateErr *strava.RateLimitError, progress SyncProgress) str
progressText := ""
if progress.Total > 0 {
remaining := progress.Total - progress.Completed
- progressText = fmt.Sprintf(" Progress: %d/%d completed, %d imported, %d skipped, %d remaining.", progress.Completed, progress.Total, progress.Imported, progress.Skipped, remaining)
+ progressText = fmt.Sprintf(" Progress: %d/%d completed, %d imported, %d skipped, %d updated, %d remaining.", progress.Completed, progress.Total, progress.Imported, progress.Skipped, progress.Updated, remaining)
}
return fmt.Sprintf("Strava %s rate limit reached.%s%s%s Re-run sync after the reset time to import remaining rides.", scope, progressText, usageText, retryText)
}