aboutsummaryrefslogtreecommitdiff
path: root/ride/store.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-24 12:07:30 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-24 12:07:30 +0200
commita9a384972649182c188396c5f996ae617d35188a (patch)
treedc5d317d33643629acb605137626eba920b0ba18 /ride/store.go
parent3646cc0d06d077a4881b611ac845c3a6ee6dd54d (diff)
Add progress bars to the long-running CLI processes (backtest, backfill, extract-osm)
Diffstat (limited to 'ride/store.go')
-rw-r--r--ride/store.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/ride/store.go b/ride/store.go
index 162b912..56cd087 100644
--- a/ride/store.go
+++ b/ride/store.go
@@ -91,7 +91,10 @@ func Save(db *sql.DB, r StoredRide) error {
return err
}
-func Backfill(db *sql.DB) (int, error) {
+// Backfill recomputes and persists stored ride values for every ride. An
+// optional reporter is invoked with the number of rides processed and the
+// total, so callers (e.g. the CLI) can render progress.
+func Backfill(db *sql.DB, reporters ...func(current, total int)) (int, error) {
rows, err := db.Query("SELECT " + columns + " FROM rides ORDER BY id")
if err != nil {
return 0, err
@@ -113,7 +116,12 @@ func Backfill(db *sql.DB) (int, error) {
return 0, err
}
backfilled := 0
- for _, item := range pending {
+ report := func(int, int) {}
+ if len(reporters) > 0 {
+ report = reporters[0]
+ }
+ for i, item := range pending {
+ report(i+1, len(pending))
if err := Save(db, item); err != nil {
slog.Warn("Failed to backfill ride values", "ride", item.ExternalID, "file", item.GPXPath, "error", err)
continue