From fe1d9de6f153f6c6826b8f62e23ad5bf01da82a7 Mon Sep 17 00:00:00 2001 From: Daniel Thomas Date: Fri, 13 Jun 2025 22:21:59 +0200 Subject: [PATCH] fix: update persisted json after updating the repo using the poll routine --- pkg/handler/http.go | 4 ---- pkg/repo/loader.go | 9 +++++++++ pkg/repo/repo.go | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/handler/http.go b/pkg/handler/http.go index 73f1b3c..6e4b540 100644 --- a/pkg/handler/http.go +++ b/pkg/handler/http.go @@ -75,10 +75,6 @@ func (h *HTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) { route := Route(strings.TrimPrefix(r.URL.Path, h.basePath+"/")) if route == RouteGetRepo { - resp := h.repo.Update() - if !resp.Success { - h.l.Warn("repo update failed — serving previously cached data", zap.String("reason", resp.ErrorMessage)) - } h.repo.WriteRepoBytes(w) w.Header().Set("Content-Type", "application/json") return diff --git a/pkg/repo/loader.go b/pkg/repo/loader.go index 6910545..010ec04 100644 --- a/pkg/repo/loader.go +++ b/pkg/repo/loader.go @@ -305,6 +305,15 @@ func (r *Repo) update(ctx context.Context) (repoRuntime int64, err error) { if r.poll { r.pollVersion = repoURL } + + // Persist the JSON buffer after successful update + if err := r.history.Add(r.JSONBufferBytes()); err != nil { + r.l.Error("Failed to persist repo after update", zap.Error(err)) + metrics.HistoryPersistFailedCounter.WithLabelValues().Inc() + } else { + r.l.Info("Successfully persisted repo after update") + } + return repoRuntime, nil } diff --git a/pkg/repo/repo.go b/pkg/repo/repo.go index 111218d..df8a0ff 100644 --- a/pkg/repo/repo.go +++ b/pkg/repo/repo.go @@ -285,6 +285,8 @@ func (r *Repo) Update() (updateResponse *responses.Update) { if historyErr != nil { r.l.Error("Could not persist current repo in history", zap.Error(historyErr)) metrics.HistoryPersistFailedCounter.WithLabelValues().Inc() + } else { + r.l.Info("Successfully persisted current repo to history") } // add some stats for _, dimension := range r.Directory() {