From 0248bdf5e7f97f2f491764d9a5be3faa3bf3a82a Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 30 May 2026 15:03:18 +0200 Subject: [PATCH] feat(metrics): invalidate the user count cache on registration Registration is the one hot path where instant freshness is worth an extra COUNT(*), so bust the cache there rather than waiting for the TTL. --- pkg/routes/api/v1/user_register.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/routes/api/v1/user_register.go b/pkg/routes/api/v1/user_register.go index 96a9c02d9..9db52c88a 100644 --- a/pkg/routes/api/v1/user_register.go +++ b/pkg/routes/api/v1/user_register.go @@ -22,6 +22,8 @@ import ( "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/db" + "code.vikunja.io/api/pkg/log" + "code.vikunja.io/api/pkg/metrics" "code.vikunja.io/api/pkg/models" "code.vikunja.io/api/pkg/user" @@ -85,5 +87,13 @@ func RegisterUser(c *echo.Context) error { return err } + // Bust the cached user count so the new registration shows up in metrics + // immediately instead of after the regular cache expiry. + if config.MetricsEnabled.GetBool() { + if err := metrics.InvalidateCount(metrics.UserCountKey); err != nil { + log.Errorf("Could not invalidate user count metric: %s", err) + } + } + return c.JSON(http.StatusOK, newUser) }