Commit d397478d authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '250041-does-not-refresh-project-snippet-statistics-on-a-read-only-instance' into 'master'

Does not refresh project/snippet statistics on a read-only instance

Closes #250041

See merge request gitlab-org/gitlab!42417
parents bf27ada5 a774061b
......@@ -37,6 +37,8 @@ class ProjectStatistics < ApplicationRecord
end
def refresh!(only: [])
return if Gitlab::Database.read_only?
COLUMNS_TO_REFRESH.each do |column, generator|
if only.empty? || only.include?(column)
public_send("update_#{column}") # rubocop:disable GitlabSecurity/PublicSend
......
......@@ -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
......
---
title: Does not refresh project/snippet statistics on a read-only instance
merge_request: 42417
author:
type: fixed
......@@ -201,6 +201,23 @@ RSpec.describe ProjectStatistics do
statistics.refresh!(only: [:commit_count])
end
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_repository_size)
expect(statistics).not_to receive(:update_wiki_size)
expect(statistics).not_to receive(:update_lfs_objects_size)
expect(statistics).not_to receive(:update_snippets_size)
expect(statistics).not_to receive(:save!)
expect(Namespaces::ScheduleAggregationWorker)
.not_to receive(:perform_async)
statistics.refresh!
end
end
end
describe '#update_commit_count' do
......
......@@ -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