]> source.dussan.org Git - redmine.git/commitdiff
Optimize users visibility check (#39857).
authorGo MAEDA <maeda@farend.jp>
Wed, 27 Dec 2023 08:07:22 +0000 (08:07 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 27 Dec 2023 08:07:22 +0000 (08:07 +0000)
Patch by Pavel Rosický.

git-svn-id: https://svn.redmine.org/redmine/trunk@22567 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/principal.rb

index 4cce97e26f997827aa96615ef42ad82dc5952bd4..25a79d768831680ff0f6784371315cb46d866167 100644 (file)
@@ -48,8 +48,8 @@ class Principal < ActiveRecord::Base
       all
     else
       view_all_active = false
-      if user.memberships.to_a.any?
-        view_all_active = user.memberships.any? {|m| m.roles.any? {|r| r.users_visibility == 'all'}}
+      if user.memberships.any?
+        view_all_active = User.where(id: user.id).joins(memberships: :roles).where("#{Role.table_name}.users_visibility = ?", 'all').any?
       else
         view_all_active = user.builtin_role.users_visibility == 'all'
       end