Commit 34e912b5 authored by Reuben Pereira's avatar Reuben Pereira

Use a hash to memoize readable_project_ids with user objects as keys

parent 8cc646fa
...@@ -13,16 +13,15 @@ module Banzai ...@@ -13,16 +13,15 @@ module Banzai
# Returns an Array of Project ids that can be read by the given user. # 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 # user - The User for which to check the projects
def readable_project_ids_for(projects, user) def readable_project_ids_for(user)
strong_memoize(:readable_project_ids_for) do @project_ids_by_user ||= {}
Project.public_or_visible_to_user(user).where("projects.id IN (?)", projects.map(&:id)).pluck(:id) @project_ids_by_user[user] ||=
end Project.public_or_visible_to_user(user).where("projects.id IN (?)", @projects_for_nodes.values.map(&:id)).pluck(:id)
end end
def can_read_reference?(user, ref_project, node) 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 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