Commit c3f50416 authored by Paco Guzman's avatar Paco Guzman

AbstractReferenceFilter caches current project_ref on RequestStore when active

Before we weren’t caching current_project_ref because normally the reference to 
the current project doesn’t include the path with namespace. But now we store 
the current project in the projects reference cache to be used for the same 
filter when accessing using path with namespace of for subsequent filters executed on the cache.
parent 7d48778c
......@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.13.0 (unreleased)
- Use gitlab-shell v3.6.2 (GIT TRACE logging)
- AbstractReferenceFilter caches project_refs on RequestStore when active
- Speed-up group milestones show page
- Log LDAP lookup errors and don't swallow unrelated exceptions. !6103 (Markus Koller)
- Add more tests for calendar contribution (ClemMakesApps)
......
......@@ -64,7 +64,7 @@ module Banzai
end
end
def project_from_ref_cache(ref)
def project_from_ref_cached(ref)
if RequestStore.active?
cache = project_refs_cache
......@@ -146,7 +146,7 @@ module Banzai
# have `gfm` and `gfm-OBJECT_NAME` class names attached for styling.
def object_link_filter(text, pattern, link_text: nil)
references_in(text, pattern) do |match, id, project_ref, matches|
project = project_from_ref_cache(project_ref)
project = project_from_ref_cached(project_ref)
if project && object = find_object_cached(project, id)
title = object_link_title(object)
......@@ -243,11 +243,27 @@ module Banzai
end
end
# Returns the projects for the given paths.
def find_projects_for_paths(paths)
def projects_relation_for_paths(paths)
Project.where_paths_in(paths).includes(:namespace)
end
# Returns projects for the given paths.
def find_projects_for_paths(paths)
if RequestStore.active?
to_query = paths - project_refs_cache.keys
unless to_query.empty?
projects_relation_for_paths(to_query).each do |project|
get_or_set_cache(project_refs_cache, project.path_with_namespace) { project }
end
end
project_refs_cache.slice(*paths).values
else
projects_relation_for_paths(paths)
end
end
def current_project_path
@current_project_path ||= project.path_with_namespace
end
......
......@@ -66,7 +66,7 @@ module Banzai
end
end
def find_projects_for_paths(paths)
def projects_relation_for_paths(paths)
super(paths).includes(:gitlab_issue_tracker_service)
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