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 ...@@ -34,6 +34,8 @@ class SnippetStatistics < ApplicationRecord
end end
def refresh! def refresh!
return if Gitlab::Database.read_only?
update_commit_count update_commit_count
update_repository_size update_repository_size
update_file_count update_file_count
......
...@@ -75,15 +75,28 @@ RSpec.describe SnippetStatistics do ...@@ -75,15 +75,28 @@ RSpec.describe SnippetStatistics do
end end
describe '#refresh!' do describe '#refresh!' do
subject { statistics.refresh! }
it 'retrieves and saves statistic data from repository' do it 'retrieves and saves statistic data from repository' do
expect(statistics).to receive(:update_commit_count) expect(statistics).to receive(:update_commit_count)
expect(statistics).to receive(:update_file_count) expect(statistics).to receive(:update_file_count)
expect(statistics).to receive(:update_repository_size) expect(statistics).to receive(:update_repository_size)
expect(statistics).to receive(:save!) 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
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