remotes: flush cached metadata when a remote's base_url changes
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

Switching a remote's backend (base_url) left the previously-cached mutable
metadata (repodata / Release / APKINDEX) served until TTL expiry, pointing
at the old upstream. cache.FlushRemote existed but was wired to nothing.

- Inject a MetadataFlusher (satisfied by *cache.Redis) into RemotesHandler.
- On update, read the existing remote first, then after a successful DB
  update flush the remote's cached metadata when base_url changed so the
  next request re-fetches fresh from the new upstream.
- A flush failure is logged as a warning and does not fail the request; the
  DB update already landed.
- Add tests: base_url change flushes exactly once, an unchanged base_url
  does not flush, and a flush error still returns 200.
This commit is contained in:
2026-08-13 07:10:02 +10:00
parent 73c0bfc670
commit e34c6570fc
4 changed files with 132 additions and 6 deletions
+1 -1
View File
@@ -175,7 +175,7 @@ func (s *Server) routes() chi.Router {
r.Mount("/api/v1", proxyHandler.Routes())
r.Mount("/v2", proxyHandler.DockerV2Routes())
remotesHandler := v2.NewRemotesHandler(s.db, map[models.PackageType]v2.Primer{
remotesHandler := v2.NewRemotesHandler(s.db, s.cache, map[models.PackageType]v2.Primer{
models.PackageGitHubRPM: s.syncer,
models.PackageGitHubDeb: s.debSyncer,
models.PackageGitHubAlpine: s.alpineSyncer,