Reduce DB load when resetting CI minute notifications
Summary
The monthly CI minute reset still puts a lot of load on the database. This is because all Namespace
models get updated instead of just resetting ones that need a reset. This part of the reset was never limited to only namespaces that need a reset, so this won't be a revert, we need to change this behavior.
Proposal
Originally brought up by @fabiopitino
I think something like this should have mitigated the problem:
diff --git a/ee/app/services/ci/minutes/batch_reset_service.rb b/ee/app/services/ci/minutes/batch_reset_service.rb index 98c8d7464d8..47da9c5b2a0 100644 --- a/ee/app/services/ci/minutes/batch_reset_service.rb +++ b/ee/app/services/ci/minutes/batch_reset_service.rb @@ -110,11 +110,13 @@ def reset_shared_runners_seconds!(namespaces) .update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current) end + # rubocop: disable CodeReuse/ActiveRecord def reset_ci_minutes_notifications!(namespaces) - namespaces.update_all( - last_ci_minutes_notification_at: nil, - last_ci_minutes_usage_notification_level: nil) + namespaces + .where('last_ci_minutes_notification_at IS NOT NULL OR last_ci_minutes_usage_notification_level IS NOT NULL') + .update_all(last_ci_minutes_notification_at: nil, last_ci_minutes_usage_notification_level: nil) end + # rubocop: enable CodeReuse/ActiveRecord end end end