summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/user_reference_filter.rb
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2017-11-06 16:52:56 +0000
committerDouwe Maan <douwe@gitlab.com>2017-11-06 16:52:56 +0000
commitbf0331dc72db658b012d58e33ca47da6d8f99d46 (patch)
treef596c4876cd50bf13afd1f3e60ccd57640b61656 /lib/banzai/filter/user_reference_filter.rb
parent34a205b308d80d600c5651cfb9694f978ef01cab (diff)
downloadgitlab-ce-bf0331dc72db658b012d58e33ca47da6d8f99d46.tar.gz
Resolve "DashboardController#activity.json is slow due to SQL"
Diffstat (limited to 'lib/banzai/filter/user_reference_filter.rb')
-rw-r--r--lib/banzai/filter/user_reference_filter.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/banzai/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb
index afb6e25963c..c7fa8a8119f 100644
--- a/lib/banzai/filter/user_reference_filter.rb
+++ b/lib/banzai/filter/user_reference_filter.rb
@@ -60,10 +60,14 @@ module Banzai
self.class.references_in(text) do |match, username|
if username == 'all' && !skip_project_check?
link_to_all(link_content: link_content)
- elsif namespace = namespaces[username.downcase]
- link_to_namespace(namespace, link_content: link_content) || match
else
- match
+ cached_call(:banzai_url_for_object, match, path: [User, username.downcase]) do
+ if namespace = namespaces[username.downcase]
+ link_to_namespace(namespace, link_content: link_content) || match
+ else
+ match
+ end
+ end
end
end
end
@@ -74,7 +78,10 @@ module Banzai
# The keys of this Hash are the namespace paths, the values the
# corresponding Namespace objects.
def namespaces
- @namespaces ||= Namespace.where_full_path_in(usernames).index_by(&:full_path).transform_keys(&:downcase)
+ @namespaces ||= Namespace.eager_load(:owner, :route)
+ .where_full_path_in(usernames)
+ .index_by(&:full_path)
+ .transform_keys(&:downcase)
end
# Returns all usernames referenced in the current document.