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/services/projects/refresh_build_artifacts_size_statistics_service.rb')
-rw-r--r--app/services/projects/refresh_build_artifacts_size_statistics_service.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/app/services/projects/refresh_build_artifacts_size_statistics_service.rb b/app/services/projects/refresh_build_artifacts_size_statistics_service.rb
index 8e006dc8c34..f11083d6c04 100644
--- a/app/services/projects/refresh_build_artifacts_size_statistics_service.rb
+++ b/app/services/projects/refresh_build_artifacts_size_statistics_service.rb
@@ -2,28 +2,31 @@
module Projects
class RefreshBuildArtifactsSizeStatisticsService
- BATCH_SIZE = 1000
+ BATCH_SIZE = 500
+ REFRESH_INTERVAL_SECONDS = 0.1
def execute
refresh = Projects::BuildArtifactsSizeRefresh.process_next_refresh!
- return unless refresh
+
+ return unless refresh&.running?
batch = refresh.next_batch(limit: BATCH_SIZE).to_a
if batch.any?
- # We are doing the sum in ruby because the query takes too long when done in SQL
- total_artifacts_size = batch.sum { |artifact| artifact.size.to_i }
+ increments = batch.map do |artifact|
+ Gitlab::Counters::Increment.new(amount: artifact.size.to_i, ref: artifact.id)
+ end
Projects::BuildArtifactsSizeRefresh.transaction do
# Mark the refresh ready for another worker to pick up and process the next batch
refresh.requeue!(batch.last.id)
- refresh.project.statistics.increment_counter(:build_artifacts_size, total_artifacts_size)
+ ProjectStatistics.bulk_increment_statistic(refresh.project, :build_artifacts_size, increments)
end
+
+ sleep REFRESH_INTERVAL_SECONDS
else
- # Remove the refresh job from the table if there are no more
- # remaining job artifacts to calculate for the given project.
- refresh.destroy!
+ refresh.schedule_finalize!
end
refresh