diff --git a/ee/app/models/ci/minutes/quota.rb b/ee/app/models/ci/minutes/quota.rb index 8945e2550d9e4c0c7e540e7e945003925ed32efa..0fbe3deacefb2c678a8edd2f40f98f7dffbec7fa 100644 --- a/ee/app/models/ci/minutes/quota.rb +++ b/ee/app/models/ci/minutes/quota.rb @@ -25,7 +25,7 @@ module Ci end def monthly_percent_used - return 0 unless enabled? + return 0 unless enabled? && any_project_enabled? return 0 if monthly_minutes == 0 100 * monthly_minutes_used.to_i / monthly_minutes @@ -81,6 +81,12 @@ module Ci private + def any_project_enabled? + strong_memoize(:any_project_enabled) do + namespace.any_project_with_shared_runners_enabled? + end + end + # TODO: rename to `enabled?` # https://gitlab.com/gitlab-org/gitlab/-/issues/332933 def limit_enabled? @@ -90,9 +96,9 @@ module Ci end def minutes_limit - return monthly_minutes if enabled? + return monthly_minutes if enabled? && any_project_enabled? - if namespace_eligible? + if namespace_eligible? && any_project_enabled? _('Unlimited') else _('Not supported') diff --git a/ee/app/views/namespaces/_shared_runner_status.html.haml b/ee/app/views/namespaces/_shared_runner_status.html.haml index 1025bdd100fd02ee61af9e66994095ef9fb794de..36a646a4589576959f0bbc3d1f9e8a6937cb9dd3 100644 --- a/ee/app/views/namespaces/_shared_runner_status.html.haml +++ b/ee/app/views/namespaces/_shared_runner_status.html.haml @@ -1,7 +1,7 @@ - namespace = local_assigns.fetch(:namespace) - minutes_quota = namespace.ci_minutes_quota -- if minutes_quota.namespace_eligible? +- if namespace.any_project_with_shared_runners_enabled? %li %span.light= _('Pipeline minutes quota:') %strong diff --git a/ee/spec/helpers/ee/namespaces_helper_spec.rb b/ee/spec/helpers/ee/namespaces_helper_spec.rb index 74708dce3d830b3ac5bb68b4173ca362d91eb4ea..d64d70e0ec3c7962a77c511bfd32ce3bd0da0f59 100644 --- a/ee/spec/helpers/ee/namespaces_helper_spec.rb +++ b/ee/spec/helpers/ee/namespaces_helper_spec.rb @@ -63,6 +63,7 @@ RSpec.describe EE::NamespacesHelper do context 'and the namespace is eligible for unlimited' do before do allow(quota).to receive(:namespace_eligible?).and_return(true) + allow(user_group).to receive(:any_project_with_shared_runners_enabled?).and_return(true) end it 'returns Unlimited for the limit section' do diff --git a/ee/spec/models/ci/minutes/quota_spec.rb b/ee/spec/models/ci/minutes/quota_spec.rb index 3bd153a9ba9240bc1014964145b6bd3753163c19..a1c04e69153f2357c0086da04e5e0d14f56b6ccb 100644 --- a/ee/spec/models/ci/minutes/quota_spec.rb +++ b/ee/spec/models/ci/minutes/quota_spec.rb @@ -68,6 +68,7 @@ RSpec.describe Ci::Minutes::Quota do before do allow(quota).to receive(:enabled?).and_return(false) allow(quota).to receive(:namespace_eligible?).and_return(namespace_eligible) + allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) end context 'when the namespace is not eligible' do @@ -114,6 +115,7 @@ RSpec.describe Ci::Minutes::Quota do context 'when limited' do before do allow(quota).to receive(:enabled?).and_return(true) + allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) namespace.shared_runners_minutes_limit = 100 end @@ -257,6 +259,7 @@ RSpec.describe Ci::Minutes::Quota do with_them do before do allow(quota).to receive(:enabled?).and_return(limit_enabled) + allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true) namespace.shared_runners_minutes_limit = monthly_limit namespace.extra_shared_runners_minutes_limit = purchased_limit namespace.namespace_statistics.shared_runners_seconds = minutes_used.minutes diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index bcad9eb6e2335b9ea9029d0d071d10a2ec1e3734..587d167520fd440c1bd9d7574e840e687626e2fa 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -202,7 +202,7 @@ RSpec.describe PipelineSerializer do # Existing numbers are high and require performance optimization # Ongoing issue: # https://gitlab.com/gitlab-org/gitlab/-/issues/225156 - expected_queries = Gitlab.ee? ? 77 : 70 + expected_queries = Gitlab.ee? ? 74 : 70 expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0)