refact pkg/database: dry decision count (#3586)

This commit is contained in:
mmetc 2025-04-24 10:25:48 +02:00 committed by GitHub
parent d46cef1bcb
commit 34e306505c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 66 deletions

View file

@ -642,7 +642,7 @@ func GetDecisionsCount(params ...any) (any, error) {
ctx := context.TODO()
count, err := dbClient.CountDecisionsByValue(ctx, value)
count, err := dbClient.CountDecisionsByValue(ctx, value, nil, false)
if err != nil {
log.Errorf("Failed to get decisions count from value '%s'", value)
return 0, nil //nolint:nilerr // This helper did not return an error before the move to expr.Function, we keep this behavior for backward compatibility
@ -670,7 +670,7 @@ func GetDecisionsSinceCount(params ...any) (any, error) {
ctx := context.TODO()
sinceTime := time.Now().UTC().Add(-sinceDuration)
count, err := dbClient.CountDecisionsSinceByValue(ctx, value, sinceTime)
count, err := dbClient.CountDecisionsByValue(ctx, value, &sinceTime, false)
if err != nil {
log.Errorf("Failed to get decisions count from value '%s'", value)
return 0, nil //nolint:nilerr // This helper did not return an error before the move to expr.Function, we keep this behavior for backward compatibility
@ -689,7 +689,7 @@ func GetActiveDecisionsCount(params ...any) (any, error) {
ctx := context.TODO()
count, err := dbClient.CountActiveDecisionsByValue(ctx, value)
count, err := dbClient.CountDecisionsByValue(ctx, value, nil, true)
if err != nil {
log.Errorf("Failed to get active decisions count from value '%s'", value)
return 0, err