summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-06-29 18:53:32 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-06-29 19:11:48 -0300
commit2446252cfd1f5a7d7329099e8d6371fcffa99971 (patch)
tree42a740e7fc2ec0b6afb358b549c229c8a2c0eaa1
parent37011af0c08a9c22cf4df0fb5655a2f2eff1117d (diff)
downloadgitlab-ce-2446252cfd1f5a7d7329099e8d6371fcffa99971.tar.gz
Expires full_path cache after project is renamed
-rw-r--r--app/models/concerns/routable.rb11
-rw-r--r--app/models/project.rb1
-rw-r--r--spec/models/concerns/routable_spec.rb12
-rw-r--r--spec/models/project_spec.rb2
4 files changed, 24 insertions, 2 deletions
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb
index ec7796a9dbb..2305e01d3f1 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 a75c5209955..862ee027e54 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 65f05121b40..be82a601b36 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 1390848ff4a..6ff4ec3d417 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