Skip to content

Commit

Permalink
Avoid N+1 queries by preloading associations
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Oct 28, 2024
1 parent 82d88bd commit 77ae6b4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/redmine_organizations/patches/project_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ def self.allowed_to_condition(user, permission, options = {})
end

# Builds a nested hash of users sorted by role and organization
# => { Role(1) => { Org(1) => [ User(1), User(2), ... ] } }
# => { Role(1) => { Org(1) => [ User(1), User(2), ... ] } }
#
# TODO: simplify / refactor / test it correctly !!!
def users_by_role_and_organization
dummy_org = Organization.new(:name => l(:label_others))
self.members.map do |member|

members = self.members.includes(:roles, user: :organization)

members.map do |member|
member.roles.map do |role|
{ :user => member.user, :role => role, :organization => member.user.organization }
end
Expand Down

0 comments on commit 77ae6b4

Please sign in to comment.