diff --git a/changelogs/unreleased/mc-bug-reduce-ci-minute-namespace-notification-db-load.yml b/changelogs/unreleased/mc-bug-reduce-ci-minute-namespace-notification-db-load.yml new file mode 100644 index 0000000000000000000000000000000000000000..9707dc4623e3268326c9474247c294766b79def6 --- /dev/null +++ b/changelogs/unreleased/mc-bug-reduce-ci-minute-namespace-notification-db-load.yml @@ -0,0 +1,5 @@ +--- +title: Reduce DB load when resetting CI minute notifications. +merge_request: 55765 +author: +type: performance diff --git a/ee/app/models/ee/namespace.rb b/ee/app/models/ee/namespace.rb index 49e40631a013c5bb27e96811fcb9f06491c71c5c..295387ba4550d9aaf32f689bd2b65f51b68e63ec 100644 --- a/ee/app/models/ee/namespace.rb +++ b/ee/app/models/ee/namespace.rb @@ -69,6 +69,11 @@ module Namespace where("EXISTS (?)", matcher) end + scope :without_last_ci_minutes_notification, -> do + where.not(last_ci_minutes_notification_at: nil) + .or(where.not(last_ci_minutes_usage_notification_level: nil)) + end + delegate :shared_runners_seconds, :shared_runners_seconds_last_reset, to: :namespace_statistics, allow_nil: true delegate :additional_purchased_storage_size, :additional_purchased_storage_size=, diff --git a/ee/app/services/ci/minutes/batch_reset_service.rb b/ee/app/services/ci/minutes/batch_reset_service.rb index 98c8d7464d840d13dee43c87e00a9c70a7c3fc7a..5761268ed8b834d4a4de3eb13ccb169d9570a1a7 100644 --- a/ee/app/services/ci/minutes/batch_reset_service.rb +++ b/ee/app/services/ci/minutes/batch_reset_service.rb @@ -111,9 +111,10 @@ def reset_shared_runners_seconds!(namespaces) end def reset_ci_minutes_notifications!(namespaces) - namespaces.update_all( + namespaces.without_last_ci_minutes_notification.update_all( last_ci_minutes_notification_at: nil, - last_ci_minutes_usage_notification_level: nil) + last_ci_minutes_usage_notification_level: nil + ) end end end