Commit 074a1797 authored by Hiroyuki Sato's avatar Hiroyuki Sato

Update the project statistics immediatelly

parent e6780501
...@@ -26,10 +26,17 @@ class ProjectCacheWorker ...@@ -26,10 +26,17 @@ class ProjectCacheWorker
end end
# rubocop: enable CodeReuse/ActiveRecord # 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 = []) def update_statistics(project, statistics = [])
return if Gitlab::Database.read_only? return if Gitlab::Database.read_only?
return unless try_obtain_lease_for(project.id, statistics) 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) UpdateProjectStatisticsWorker.perform_in(LEASE_TIMEOUT, project.id, statistics)
end end
......
...@@ -86,6 +86,10 @@ describe ProjectCacheWorker do ...@@ -86,6 +86,10 @@ describe ProjectCacheWorker do
it 'updates the project statistics' do it 'updates the project statistics' do
stub_exclusive_lease(lease_key, timeout: lease_timeout) 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) expect(UpdateProjectStatisticsWorker).to receive(:perform_in)
.with(lease_timeout, project.id, statistics.map(&:to_sym)) .with(lease_timeout, project.id, statistics.map(&:to_sym))
.and_call_original .and_call_original
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment