diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /app/models/namespace/root_storage_statistics.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'app/models/namespace/root_storage_statistics.rb')
-rw-r--r-- | app/models/namespace/root_storage_statistics.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/app/models/namespace/root_storage_statistics.rb b/app/models/namespace/root_storage_statistics.rb index 99e32537595..ee04ec39b1e 100644 --- a/app/models/namespace/root_storage_statistics.rb +++ b/app/models/namespace/root_storage_statistics.rb @@ -27,10 +27,17 @@ class Namespace::RootStorageStatistics < ApplicationRecord update!(merged_attributes) end + def self.namespace_statistics_attributes + %w(storage_size dependency_proxy_size) + end + private def merged_attributes - attributes_from_project_statistics.merge!(attributes_from_personal_snippets) { |key, v1, v2| v1 + v2 } + attributes_from_project_statistics.merge!( + attributes_from_personal_snippets, + attributes_from_namespace_statistics + ) { |key, v1, v2| v1 + v2 } end def attributes_from_project_statistics @@ -68,6 +75,27 @@ class Namespace::RootStorageStatistics < ApplicationRecord .where(author: namespace.owner_id) .select("COALESCE(SUM(s.repository_size), 0) AS #{SNIPPETS_SIZE_STAT_NAME}") end + + def from_namespace_statistics + namespace + .self_and_descendants + .joins("INNER JOIN namespace_statistics ns ON ns.namespace_id = namespaces.id") + .select( + 'COALESCE(SUM(ns.storage_size), 0) AS storage_size', + 'COALESCE(SUM(ns.dependency_proxy_size), 0) AS dependency_proxy_size' + ) + end + + def attributes_from_namespace_statistics + # At the moment, only groups can have some storage data because of dependency proxy assets. + # Therefore, if the namespace is not a group one, there is no need to perform + # the query. If this changes in the future and we add some sort of resource to + # users that it's store in NamespaceStatistics, we will need to remove this + # guard clause. + return {} unless namespace.group_namespace? + + from_namespace_statistics.take.slice(*self.class.namespace_statistics_attributes) + end end Namespace::RootStorageStatistics.prepend_mod_with('Namespace::RootStorageStatistics') |