diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 19:00:14 +0000 |
commit | 05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch) | |
tree | 11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/services/projects/refresh_build_artifacts_size_statistics_service.rb | |
parent | ec73467c23693d0db63a797d10194da9e72a74af (diff) | |
download | gitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz |
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
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.rb | 19 |
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 |