diff options
Diffstat (limited to 'app/models/namespace/root_storage_statistics.rb')
-rw-r--r-- | app/models/namespace/root_storage_statistics.rb | 31 |
1 files changed, 29 insertions, 2 deletions
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 |