mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Improve performance of Principal.member_of scope
The 'join' turns to be slow for large numbers of members (>20k). Using a sub-query like in Principal.not_member_of is more efficient and performance is the same for smaller values. git-svn-id: http://svn.redmine.org/redmine/trunk@13139 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
eaac0eff08
commit
1914d1a159
@ -61,7 +61,7 @@ class Principal < ActiveRecord::Base
|
||||
where("1=0")
|
||||
else
|
||||
ids = projects.map(&:id)
|
||||
active.uniq.joins(:members).where("#{Member.table_name}.project_id IN (?)", ids)
|
||||
active.where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
||||
end
|
||||
}
|
||||
# Principals that are not members of projects
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user