diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index ec7796a9dbb0f0b245bc4d920f9e8da3a29f0dca..2305e01d3f1bcc2074d4b251534f2bcfa094859f 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -103,8 +103,11 @@ module Routable def full_path return uncached_full_path unless RequestStore.active? - key = "routable/full_path/#{self.class.name}/#{self.id}" - RequestStore[key] ||= uncached_full_path + RequestStore[full_path_key] ||= uncached_full_path + end + + def expires_full_path_cache + RequestStore.delete(full_path_key) if RequestStore.active? end def build_full_path @@ -135,6 +138,10 @@ module Routable path_changed? || parent_changed? end + def full_path_key + @full_path_key ||= "routable/full_path/#{self.class.name}/#{self.id}" + end + def build_full_name if parent && name parent.human_name + ' / ' + name diff --git a/app/models/project.rb b/app/models/project.rb index a75c5209955ff801c1526a15be059247d38c168f..862ee027e5406c148001b87dccdfa9e528daca5f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -963,6 +963,7 @@ class Project < ActiveRecord::Base begin gitlab_shell.mv_repository(repository_storage_path, "#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") send_move_instructions(old_path_with_namespace) + expires_full_path_cache @old_path_with_namespace = old_path_with_namespace diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 65f05121b403bf538f465a57c3e692f1f212e160..be82a601b36de4607cbf5c72fb0f20fd2ea66243 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -132,6 +132,18 @@ describe Group, 'Routable' do end end + describe '#expires_full_path_cache' do + context 'with RequestStore active', :request_store do + it 'expires the full_path cache' do + expect(group).to receive(:uncached_full_path).twice.and_call_original + + 3.times { group.full_path } + group.expires_full_path_cache + 3.times { group.full_path } + end + end + end + describe '#full_name' do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1390848ff4afb00ddaabe29378e0e5479a447c8d..6ff4ec3d417dbe1d2e3447b54f9af7c42890d1fa 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1216,6 +1216,8 @@ describe Project, models: true do expect(project).to receive(:expire_caches_before_rename) + expect(project).to receive(:expires_full_path_cache) + project.rename_repo end