Commit 2792a502 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'geo/project-avoid-caching-data-on-first-access' into 'master'

Don't try to update a project's external service caches on a secondary Geo node

See merge request !1273
parents 6fca7f0a b6a99126
......@@ -792,7 +792,7 @@ class Project < ActiveRecord::Base
end
def cache_has_external_issue_tracker
update_column(:has_external_issue_tracker, services.external_issue_trackers.any?)
update_column(:has_external_issue_tracker, services.external_issue_trackers.any?) unless Gitlab::Geo.secondary?
end
def has_wiki?
......@@ -812,7 +812,7 @@ class Project < ActiveRecord::Base
end
def cache_has_external_wiki
update_column(:has_external_wiki, services.external_wikis.any?)
update_column(:has_external_wiki, services.external_wikis.any?) unless Gitlab::Geo.secondary?
end
def find_or_initialize_services
......
---
title: Don't try to update a project's external service caches on a secondary Geo node
merge_request:
author:
......@@ -729,6 +729,44 @@ describe Project, models: true do
project.cache_has_external_issue_tracker
end.to change { project.has_external_issue_tracker}.to(false)
end
it 'does not cache data when in a secondary gitlab geo node' do
allow(Gitlab::Geo).to receive(:secondary?) { true }
expect do
project.cache_has_external_issue_tracker
end.not_to change { project.has_external_issue_tracker }
end
end
describe '#cache_has_external_wiki' do
let(:project) { create(:empty_project, has_external_wiki: nil) }
it 'stores true if there is any external_wikis' do
services = double(:service, external_wikis: [ExternalWikiService.new])
expect(project).to receive(:services).and_return(services)
expect do
project.cache_has_external_wiki
end.to change { project.has_external_wiki}.to(true)
end
it 'stores false if there is no external_wikis' do
services = double(:service, external_wikis: [])
expect(project).to receive(:services).and_return(services)
expect do
project.cache_has_external_wiki
end.to change { project.has_external_wiki}.to(false)
end
it 'does not cache data when in a secondary gitlab geo node' do
allow(Gitlab::Geo).to receive(:secondary?) { true }
expect do
project.cache_has_external_wiki
end.not_to change { project.has_external_wiki }
end
end
describe '#has_wiki?' do
......
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