Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/project_statistics.rb')
-rw-r--r--app/models/project_statistics.rb52
1 files changed, 17 insertions, 35 deletions
diff --git a/app/models/project_statistics.rb b/app/models/project_statistics.rb
index 0570be85ad1..506f6305791 100644
--- a/app/models/project_statistics.rb
+++ b/app/models/project_statistics.rb
@@ -11,21 +11,21 @@ class ProjectStatistics < ApplicationRecord
attribute :snippets_size, default: 0
counter_attribute :build_artifacts_size
+ counter_attribute :packages_size
- counter_attribute_after_flush do |project_statistic|
- project_statistic.refresh_storage_size!
+ counter_attribute_after_commit do |project_statistics|
+ project_statistics.refresh_storage_size!
- Namespaces::ScheduleAggregationWorker.perform_async(project_statistic.namespace_id)
+ Namespaces::ScheduleAggregationWorker.perform_async(project_statistics.namespace_id)
end
before_save :update_storage_size
COLUMNS_TO_REFRESH = [:repository_size, :wiki_size, :lfs_objects_size, :commit_count, :snippets_size, :uploads_size, :container_registry_size].freeze
- INCREMENTABLE_COLUMNS = {
- packages_size: %i[storage_size],
- pipeline_artifacts_size: %i[storage_size],
- snippets_size: %i[storage_size]
- }.freeze
+ INCREMENTABLE_COLUMNS = [
+ :pipeline_artifacts_size,
+ :snippets_size
+ ].freeze
NAMESPACE_RELATABLE_COLUMNS = [:repository_size, :wiki_size, :lfs_objects_size, :uploads_size, :container_registry_size].freeze
STORAGE_SIZE_COMPONENTS = [
:repository_size,
@@ -120,35 +120,27 @@ class ProjectStatistics < ApplicationRecord
# we have to update the storage_size separately.
#
# For counter attributes, storage_size will be refreshed after the counter is flushed,
- # through counter_attribute_after_flush
+ # through counter_attribute_after_commit
#
# For non-counter attributes, storage_size is updated depending on key => [columns] in INCREMENTABLE_COLUMNS
def self.increment_statistic(project, key, amount)
- raise ArgumentError, "Cannot increment attribute: #{key}" unless incrementable_attribute?(key)
- return if amount == 0
-
project.statistics.try do |project_statistics|
- if counter_attribute_enabled?(key)
- project_statistics.delayed_increment_counter(key, amount)
- else
- project_statistics.legacy_increment_statistic(key, amount)
- end
+ project_statistics.increment_statistic(key, amount)
end
end
- def self.incrementable_attribute?(key)
- INCREMENTABLE_COLUMNS.key?(key) || counter_attribute_enabled?(key)
- end
-
- def legacy_increment_statistic(key, amount)
- increment_columns!(key, amount)
+ def increment_statistic(key, amount)
+ raise ArgumentError, "Cannot increment attribute: #{key}" unless incrementable_attribute?(key)
- Namespaces::ScheduleAggregationWorker.perform_async( # rubocop: disable CodeReuse/Worker
- project.namespace_id)
+ increment_counter(key, amount)
end
private
+ def incrementable_attribute?(key)
+ INCREMENTABLE_COLUMNS.include?(key) || counter_attribute_enabled?(key)
+ end
+
def storage_size_components
STORAGE_SIZE_COMPONENTS
end
@@ -157,16 +149,6 @@ class ProjectStatistics < ApplicationRecord
storage_size_components.map { |component| "COALESCE (#{component}, 0)" }.join(' + ').freeze
end
- def increment_columns!(key, amount)
- increments = { key => amount }
- additional = INCREMENTABLE_COLUMNS.fetch(key, [])
- additional.each do |column|
- increments[column] = amount
- end
-
- update_counters_with_lease(increments)
- end
-
def schedule_namespace_aggregation_worker
run_after_commit do
Namespaces::ScheduleAggregationWorker.perform_async(project.namespace_id)