Commit 1028e053 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add parent full path to project list cache key

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f938f944
...@@ -157,7 +157,16 @@ module ProjectsHelper ...@@ -157,7 +157,16 @@ module ProjectsHelper
end end
def project_list_cache_key(project) 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 << pipeline_status_cache_key(project.pipeline_status) if project.pipeline_status.has_status?
key key
......
...@@ -224,6 +224,10 @@ class Namespace < ActiveRecord::Base ...@@ -224,6 +224,10 @@ class Namespace < ActiveRecord::Base
parent.present? parent.present?
end end
def parent_full_path
full_path.split('/')[0...-1].join('/')
end
private private
def repository_storage_paths def repository_storage_paths
......
---
title: Add parent full path to project list cache key
merge_request: 11325
author:
...@@ -70,6 +70,12 @@ describe ProjectsHelper do ...@@ -70,6 +70,12 @@ describe ProjectsHelper do
expect(helper.project_list_cache_key(project)).to include(project.namespace.cache_key) expect(helper.project_list_cache_key(project)).to include(project.namespace.cache_key)
end 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 it "includes the project" do
expect(helper.project_list_cache_key(project)).to include(project.cache_key) expect(helper.project_list_cache_key(project)).to include(project.cache_key)
end end
......
...@@ -332,4 +332,10 @@ describe Namespace, models: true do ...@@ -332,4 +332,10 @@ describe Namespace, models: true do
it { expect(group.all_projects.to_a).to eq([project2, project1]) } it { expect(group.all_projects.to_a).to eq([project2, project1]) }
end end
describe '#parent_full_path' do
let(:namespace) { create(:group, :nested) }
it { expect(namespace.parent_full_path).to eq(namespace.parent.path) }
end
end end
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