diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 09:06:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 09:06:25 +0300 |
commit | 45a05a8ba33101ffcd154ee84307885b48b17962 (patch) | |
tree | 037cf2ef8575f6f4900f6ec009ca2ac46a539192 /app/models/concerns/update_project_statistics.rb | |
parent | 284ae7dd7536df63fc6dd971f65ca420e26d2f05 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/update_project_statistics.rb')
-rw-r--r-- | app/models/concerns/update_project_statistics.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/app/models/concerns/update_project_statistics.rb b/app/models/concerns/update_project_statistics.rb index 869b3490f3f..a84fb1cf56d 100644 --- a/app/models/concerns/update_project_statistics.rb +++ b/app/models/concerns/update_project_statistics.rb @@ -49,8 +49,7 @@ module UpdateProjectStatistics attr = self.class.statistic_attribute delta = read_attribute(attr).to_i - attribute_before_last_save(attr).to_i - update_project_statistics(delta) - schedule_namespace_aggregation_worker + schedule_update_project_statistic(delta) end def update_project_statistics_attribute_changed? @@ -58,24 +57,35 @@ module UpdateProjectStatistics end def update_project_statistics_after_destroy - update_project_statistics(-read_attribute(self.class.statistic_attribute).to_i) + delta = -read_attribute(self.class.statistic_attribute).to_i - schedule_namespace_aggregation_worker + schedule_update_project_statistic(delta) end def project_destroyed? project.pending_delete? end - def update_project_statistics(delta) - ProjectStatistics.increment_statistic(project_id, self.class.project_statistics_name, delta) - end + def schedule_update_project_statistic(delta) + return if delta.zero? + + if Feature.enabled?(:update_project_statistics_after_commit, default_enabled: true) + # Update ProjectStatistics after the transaction + run_after_commit do + ProjectStatistics.increment_statistic( + project_id, self.class.project_statistics_name, delta) + end + else + # Use legacy-way to update within transaction + ProjectStatistics.increment_statistic( + project_id, self.class.project_statistics_name, delta) + end - def schedule_namespace_aggregation_worker run_after_commit do next if project.nil? - Namespaces::ScheduleAggregationWorker.perform_async(project.namespace_id) + Namespaces::ScheduleAggregationWorker.perform_async( + project.namespace_id) end end end |