feat: purge expired api keys in dbpurge (#20863)

closes https://github.com/coder/coder/issues/19889

This is in response to a migration in v2.27 that takes very long on deployments with large `api_key` tables.
This commit is contained in:
Steven Masley
2025-11-24 10:24:32 -06:00
committed by GitHub
parent c6631e1e50
commit cefe07d074
10 changed files with 197 additions and 4 deletions
@@ -312,6 +312,13 @@ func (m queryMetricsStore) DeleteCustomRole(ctx context.Context, arg database.De
return r0
}
func (m queryMetricsStore) DeleteExpiredAPIKeys(ctx context.Context, arg database.DeleteExpiredAPIKeysParams) (int64, error) {
start := time.Now()
r0, r1 := m.s.DeleteExpiredAPIKeys(ctx, arg)
m.queryLatencies.WithLabelValues("DeleteExpiredAPIKeys").Observe(time.Since(start).Seconds())
return r0, r1
}
func (m queryMetricsStore) DeleteExternalAuthLink(ctx context.Context, arg database.DeleteExternalAuthLinkParams) error {
start := time.Now()
r0 := m.s.DeleteExternalAuthLink(ctx, arg)