diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/models/namespace | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/models/namespace')
-rw-r--r-- | app/models/namespace/aggregation_schedule.rb | 12 | ||||
-rw-r--r-- | app/models/namespace/root_storage_statistics.rb | 31 |
2 files changed, 35 insertions, 8 deletions
diff --git a/app/models/namespace/aggregation_schedule.rb b/app/models/namespace/aggregation_schedule.rb index cd7d4fc409a..e08c08f9ced 100644 --- a/app/models/namespace/aggregation_schedule.rb +++ b/app/models/namespace/aggregation_schedule.rb @@ -12,11 +12,11 @@ class Namespace::AggregationSchedule < ApplicationRecord after_create :schedule_root_storage_statistics - def self.default_lease_timeout - if Feature.enabled?(:remove_namespace_aggregator_delay) - 30.minutes.to_i + def default_lease_timeout + if Feature.enabled?(:reduce_aggregation_schedule_lease, namespace.root_ancestor) + 2.minutes.to_i else - 1.hour.to_i + 30.minutes.to_i end end @@ -27,7 +27,7 @@ class Namespace::AggregationSchedule < ApplicationRecord .perform_async(namespace_id) Namespaces::RootStatisticsWorker - .perform_in(self.class.default_lease_timeout, namespace_id) + .perform_in(default_lease_timeout, namespace_id) end end end @@ -36,7 +36,7 @@ class Namespace::AggregationSchedule < ApplicationRecord # Used by ExclusiveLeaseGuard def lease_timeout - self.class.default_lease_timeout + default_lease_timeout end # Used by ExclusiveLeaseGuard diff --git a/app/models/namespace/root_storage_statistics.rb b/app/models/namespace/root_storage_statistics.rb index 77974a0f36b..0443e1d9231 100644 --- a/app/models/namespace/root_storage_statistics.rb +++ b/app/models/namespace/root_storage_statistics.rb @@ -45,8 +45,9 @@ class Namespace::RootStorageStatistics < ApplicationRecord attributes_from_project_statistics.merge!( attributes_from_personal_snippets, attributes_from_namespace_statistics, - attributes_for_container_registry_size - ) { |key, v1, v2| v1 + v2 } + attributes_for_container_registry_size, + attributes_for_forks_statistics + ) { |_, v1, v2| v1 + v2 } end def attributes_for_container_registry_size @@ -58,6 +59,32 @@ class Namespace::RootStorageStatistics < ApplicationRecord }.with_indifferent_access end + def attributes_for_forks_statistics + return {} unless ::Feature.enabled?(:root_storage_statistics_calculate_forks, namespace) + + visibility_levels_to_storage_size_columns = { + Gitlab::VisibilityLevel::PRIVATE => :private_forks_storage_size, + Gitlab::VisibilityLevel::INTERNAL => :internal_forks_storage_size, + Gitlab::VisibilityLevel::PUBLIC => :public_forks_storage_size + } + + defaults = { + private_forks_storage_size: 0, + internal_forks_storage_size: 0, + public_forks_storage_size: 0 + } + + defaults.merge(for_forks_statistics.transform_keys { |k| visibility_levels_to_storage_size_columns[k] }) + end + + def for_forks_statistics + all_projects + .joins([:statistics, :fork_network]) + .where('fork_networks.root_project_id != projects.id') + .group('projects.visibility_level') + .sum('project_statistics.storage_size') + end + def attributes_from_project_statistics from_project_statistics .take |