Does not refresh snippet statistics on read-only instance

SnippetStatistics#refresh! may be run on a Geo secondary
parent 28aafc89
......@@ -34,6 +34,8 @@ class SnippetStatistics < ApplicationRecord
end
def refresh!
return if Gitlab::Database.read_only?
update_commit_count
update_repository_size
update_file_count
......
......@@ -75,15 +75,28 @@ RSpec.describe SnippetStatistics do
end
describe '#refresh!' do
subject { statistics.refresh! }
it 'retrieves and saves statistic data from repository' do
expect(statistics).to receive(:update_commit_count)
expect(statistics).to receive(:update_file_count)
expect(statistics).to receive(:update_repository_size)
expect(statistics).to receive(:save!)
subject
statistics.refresh!
end
context 'when the database is read-only' do
it 'does nothing' do
allow(Gitlab::Database).to receive(:read_only?) { true }
expect(statistics).not_to receive(:update_commit_count)
expect(statistics).not_to receive(:update_file_count)
expect(statistics).not_to receive(:update_repository_size)
expect(statistics).not_to receive(:save!)
expect(Namespaces::ScheduleAggregationWorker)
.not_to receive(:perform_async)
statistics.refresh!
end
end
end
......
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