Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Cache Principal.default scope to reduce the number of queries on the Capabilities.default scope.

Dombi Attilaf2fb7f6ffd04
diff --git a/app/models/principals/scopes/visible.rb b/app/models/principals/scopes/visible.rb
index 077f425373c..123d92262e1 100644
--- a/app/models/principals/scopes/visible.rb
+++ b/app/models/principals/scopes/visible.rb
@@ -36,13 +36,14 @@ module Principals::Scopes
class_methods do
def visible(user = ::User.current)
- if user.allowed_in_any_project?(:manage_members) ||
- user.allowed_globally?(:manage_user) ||
- user.allowed_in_any_project?(:share_work_packages)
- all
- else
- in_visible_project_or_me(user)
- end
+ RequestStore[:"principal_default_scope_#{user.id}"] ||=
+ if user.allowed_in_any_project?(:manage_members) ||
+ user.allowed_globally?(:manage_user) ||
+ user.allowed_in_any_project?(:share_work_packages)
+ all
+ else
+ in_visible_project_or_me(user)
+ end
end
end
end