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.
This commit is contained in:
kolaente 2026-05-30 15:03:18 +02:00 committed by kolaente
parent 9e3e884dac
commit 0248bdf5e7
1 changed files with 10 additions and 0 deletions

View File

@ -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)
}