From 1028e05378f1fd25b49d95f36cf577a2b819844d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 12 May 2017 13:33:26 +0300 Subject: Add parent full path to project list cache key Signed-off-by: Dmitriy Zaporozhets --- app/helpers/projects_helper.rb | 11 ++++++++++- app/models/namespace.rb | 4 ++++ changelogs/unreleased/dz-project-list-cache-key.yml | 4 ++++ spec/helpers/projects_helper_spec.rb | 6 ++++++ spec/models/namespace_spec.rb | 6 ++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/dz-project-list-cache-key.yml diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 78b54dc20e5..fd85217debf 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -157,7 +157,16 @@ module ProjectsHelper end def project_list_cache_key(project) - key = [project.namespace.cache_key, project.cache_key, controller.controller_name, controller.action_name, current_application_settings.cache_key, 'v2.4'] + key = [ + 'parent/' + project.namespace.parent_full_path, + project.namespace.cache_key, + project.cache_key, + controller.controller_name, + controller.action_name, + current_application_settings.cache_key, + 'v2.4' + ] + key << pipeline_status_cache_key(project.pipeline_status) if project.pipeline_status.has_status? key diff --git a/app/models/namespace.rb b/app/models/namespace.rb index a7ede5e3b9e..cf82b56cc7a 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -224,6 +224,10 @@ class Namespace < ActiveRecord::Base parent.present? end + def parent_full_path + full_path.split('/')[0...-1].join('/') + end + private def repository_storage_paths diff --git a/changelogs/unreleased/dz-project-list-cache-key.yml b/changelogs/unreleased/dz-project-list-cache-key.yml new file mode 100644 index 00000000000..79d89b1c509 --- /dev/null +++ b/changelogs/unreleased/dz-project-list-cache-key.yml @@ -0,0 +1,4 @@ +--- +title: Add parent full path to project list cache key +merge_request: 11325 +author: diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index be97973c693..ceabf0caf31 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -70,6 +70,12 @@ describe ProjectsHelper do expect(helper.project_list_cache_key(project)).to include(project.namespace.cache_key) end + it "includes the parent namespace in case of subgroup" do + project = create(:project, group: create(:group, :nested)) + + expect(helper.project_list_cache_key(project)).to include("parent/#{project.namespace.parent.path}") + end + it "includes the project" do expect(helper.project_list_cache_key(project)).to include(project.cache_key) end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 8624616316c..ca61e34b78e 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -332,4 +332,10 @@ describe Namespace, models: true do it { expect(group.all_projects.to_a).to eq([project2, project1]) } end + + describe '#parent_full_path' do + let(:namespace) { create(:group, :nested) } + + it { expect(namespace.parent_full_path).to eq(namespace.parent.path) } + end end -- cgit v1.2.1 From bbd1be002b15ad50b559c217c4e2f9d50a79ef20 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 12 May 2017 18:26:01 +0300 Subject: Change project list cache key to use route.cache_key instead of namespace Signed-off-by: Dmitriy Zaporozhets --- app/helpers/projects_helper.rb | 3 +-- app/models/namespace.rb | 4 ---- app/models/route.rb | 2 +- changelogs/unreleased/dz-project-list-cache-key.yml | 2 +- spec/helpers/projects_helper_spec.rb | 10 ++-------- spec/models/namespace_spec.rb | 6 ------ 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index fd85217debf..98bbcfaaba5 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -158,8 +158,7 @@ module ProjectsHelper def project_list_cache_key(project) key = [ - 'parent/' + project.namespace.parent_full_path, - project.namespace.cache_key, + project.route.cache_key, project.cache_key, controller.controller_name, controller.action_name, diff --git a/app/models/namespace.rb b/app/models/namespace.rb index cf82b56cc7a..a7ede5e3b9e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -224,10 +224,6 @@ class Namespace < ActiveRecord::Base parent.present? end - def parent_full_path - full_path.split('/')[0...-1].join('/') - end - private def repository_storage_paths diff --git a/app/models/route.rb b/app/models/route.rb index 12a7fa3d01b..be77b8b51a5 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -35,7 +35,7 @@ class Route < ActiveRecord::Base old_path = route.path # Callbacks must be run manually - route.update_columns(attributes) + route.update_columns(attributes.merge(updated_at: Time.now)) # We are not calling route.delete_conflicting_redirects here, in hopes # of avoiding deadlocks. The parent (self, in this method) already diff --git a/changelogs/unreleased/dz-project-list-cache-key.yml b/changelogs/unreleased/dz-project-list-cache-key.yml index 79d89b1c509..9e4826e686a 100644 --- a/changelogs/unreleased/dz-project-list-cache-key.yml +++ b/changelogs/unreleased/dz-project-list-cache-key.yml @@ -1,4 +1,4 @@ --- -title: Add parent full path to project list cache key +title: Use route.cache_key for project list cache key merge_request: 11325 author: diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index ceabf0caf31..54c5ba57bdf 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -66,14 +66,8 @@ describe ProjectsHelper do describe "#project_list_cache_key", redis: true do let(:project) { create(:project) } - it "includes the namespace" do - expect(helper.project_list_cache_key(project)).to include(project.namespace.cache_key) - end - - it "includes the parent namespace in case of subgroup" do - project = create(:project, group: create(:group, :nested)) - - expect(helper.project_list_cache_key(project)).to include("parent/#{project.namespace.parent.path}") + it "includes the route" do + expect(helper.project_list_cache_key(project)).to include(project.route.cache_key) end it "includes the project" do diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index ca61e34b78e..8624616316c 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -332,10 +332,4 @@ describe Namespace, models: true do it { expect(group.all_projects.to_a).to eq([project2, project1]) } end - - describe '#parent_full_path' do - let(:namespace) { create(:group, :nested) } - - it { expect(namespace.parent_full_path).to eq(namespace.parent.path) } - end end -- cgit v1.2.1