diff options
author | Hiroyuki Sato <sathiroyuki@gmail.com> | 2019-04-04 18:18:17 +0300 |
---|---|---|
committer | Hiroyuki Sato <sathiroyuki@gmail.com> | 2019-04-04 18:22:56 +0300 |
commit | 074a1797fe581c8eb5cc65bd56af584d5c500688 (patch) | |
tree | b4ffd9f8d4aee1b9792d7b1e8e2e505f1630f090 | |
parent | e6780501cbfd0cae31fadd15b2964204171091cc (diff) |
Update the project statistics immediatelly
-rw-r--r-- | app/workers/project_cache_worker.rb | 7 | ||||
-rw-r--r-- | spec/workers/project_cache_worker_spec.rb | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb index 2b25b96a6f8..5f4972d8f93 100644 --- a/app/workers/project_cache_worker.rb +++ b/app/workers/project_cache_worker.rb @@ -26,10 +26,17 @@ class ProjectCacheWorker end # rubocop: enable CodeReuse/ActiveRecord + # NOTE: triggering both an immediate update and one in 15 minutes if we + # successfully obtain the lease. That way, we only need to wait for the + # statistics to become accurate if they were already updated once in the + # last 15 minutes. def update_statistics(project, statistics = []) return if Gitlab::Database.read_only? return unless try_obtain_lease_for(project.id, statistics) + Rails.logger.info("Updating statistics for project #{project.id}") + + project.statistics.refresh!(only: statistics) UpdateProjectStatisticsWorker.perform_in(LEASE_TIMEOUT, project.id, statistics) end diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb index 7053bfc2bfd..d2445f420f8 100644 --- a/spec/workers/project_cache_worker_spec.rb +++ b/spec/workers/project_cache_worker_spec.rb @@ -86,6 +86,10 @@ describe ProjectCacheWorker do it 'updates the project statistics' do stub_exclusive_lease(lease_key, timeout: lease_timeout) + expect(project.statistics).to receive(:refresh!) + .with(only: statistics.map(&:to_sym)) + .and_call_original + expect(UpdateProjectStatisticsWorker).to receive(:perform_in) .with(lease_timeout, project.id, statistics.map(&:to_sym)) .and_call_original |