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 ...@@ -37,6 +37,8 @@ class ProjectStatistics < ApplicationRecord
end end
def refresh!(only: []) def refresh!(only: [])
return if Gitlab::Database.read_only?
COLUMNS_TO_REFRESH.each do |column, generator| COLUMNS_TO_REFRESH.each do |column, generator|
if only.empty? || only.include?(column) if only.empty? || only.include?(column)
public_send("update_#{column}") # rubocop:disable GitlabSecurity/PublicSend public_send("update_#{column}") # rubocop:disable GitlabSecurity/PublicSend
......
...@@ -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
......
---
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 ...@@ -201,6 +201,23 @@ RSpec.describe ProjectStatistics do
statistics.refresh!(only: [:commit_count]) statistics.refresh!(only: [:commit_count])
end end
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 end
describe '#update_commit_count' do describe '#update_commit_count' do
......
...@@ -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