summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReuben Pereira <reuben453@gmail.com>2018-07-31 00:48:59 +0530
committerReuben Pereira <reuben453@gmail.com>2018-07-31 00:48:59 +0530
commit34e912b538b54619920b714b5177798597758808 (patch)
treee51de0e7a926a8f042cee2ef2f87376ad3006913 /lib
parent8cc646fa0ec05820c83a163df74605f04c8877ea (diff)
downloadgitlab-ce-34e912b538b54619920b714b5177798597758808.tar.gz
Use a hash to memoize readable_project_ids with user objects as keys
Diffstat (limited to 'lib')
-rw-r--r--lib/banzai/reference_parser/project_parser.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/banzai/reference_parser/project_parser.rb b/lib/banzai/reference_parser/project_parser.rb
index a329af42681..2a33b00ddbd 100644
--- a/lib/banzai/reference_parser/project_parser.rb
+++ b/lib/banzai/reference_parser/project_parser.rb
@@ -13,16 +13,15 @@ module Banzai
# Returns an Array of Project ids that can be read by the given user.
#
- # projects - The projects to reduce down to those readable by the user.
# user - The User for which to check the projects
- def readable_project_ids_for(projects, user)
- strong_memoize(:readable_project_ids_for) do
- Project.public_or_visible_to_user(user).where("projects.id IN (?)", projects.map(&:id)).pluck(:id)
- end
+ def readable_project_ids_for(user)
+ @project_ids_by_user ||= {}
+ @project_ids_by_user[user] ||=
+ Project.public_or_visible_to_user(user).where("projects.id IN (?)", @projects_for_nodes.values.map(&:id)).pluck(:id)
end
def can_read_reference?(user, ref_project, node)
- readable_project_ids_for(@projects_for_nodes.values, user).include?(ref_project.try(:id))
+ readable_project_ids_for(user).include?(ref_project.try(:id))
end
end
end