Commit 9c529b3d authored by Yorick Peterse's avatar Yorick Peterse Committed by Alejandro Rodríguez

Fix flushing caches when using a GEO secondary

This is not the nicest solution since it duplicates some logic from CE's
"perform" method, but it's the best solution for now.
parent 7f042cf0
......@@ -5,9 +5,9 @@ module EE
# This module is intended to encapsulate EE-specific methods
# and be **prepended** in the `ProjectCacheWorker` class.
module ProjectCacheWorker
def update_caches(project_id)
def perform(*args)
if ::Gitlab::Geo.secondary?
update_geo_caches(project_id)
perform_geo_secondary(*args)
else
super
end
......@@ -17,14 +17,12 @@ module EE
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
def update_geo_caches(project_id)
project = Project.find(project_id)
def perform_geo_secondary(project_id, refresh = [])
project = Project.find_by(id: project_id)
return unless project.repository.exists?
return unless project && project.repository.exists?
if project.repository.root_ref
project.repository.build_cache
end
project.repository.refresh_method_caches(refresh.map(&:to_sym))
end
end
end
......
......@@ -52,11 +52,12 @@ describe ProjectCacheWorker do
context 'when in Geo secondary node' do
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
end
it 'updates only non database cache' do
expect_any_instance_of(Repository).to receive(:build_cache).and_call_original
expect_any_instance_of(Repository).to receive(:refresh_method_caches).
and_call_original
expect_any_instance_of(Project).not_to receive(:update_repository_size)
expect_any_instance_of(Project).not_to receive(:update_commit_count)
......
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