Optimize Project#notified_users to improve issue create/update speed (#23328).

Patch by Holger Just (@hjust).


git-svn-id: https://svn.redmine.org/redmine/trunk@22590 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-01-04 01:23:25 +00:00
parent 70bd44395d
commit 02fbe55855

View File

@@ -34,6 +34,7 @@ class Project < ActiveRecord::Base
# Memberships of active users only # Memberships of active users only
has_many :members, has_many :members,
lambda {joins(:principal).where(:users => {:type => 'User', :status => Principal::STATUS_ACTIVE})} lambda {joins(:principal).where(:users => {:type => 'User', :status => Principal::STATUS_ACTIVE})}
has_many :users, through: :members
has_many :enabled_modules, :dependent => :delete_all has_many :enabled_modules, :dependent => :delete_all
has_and_belongs_to_many :trackers, lambda {order(:position)} has_and_belongs_to_many :trackers, lambda {order(:position)}
has_many :issues, :dependent => :destroy has_many :issues, :dependent => :destroy
@@ -625,13 +626,7 @@ class Project < ActiveRecord::Base
# Returns the users that should be notified on project events # Returns the users that should be notified on project events
def notified_users def notified_users
# TODO: User part should be extracted to User#notify_about? users.where('members.mail_notification = ? OR users.mail_notification = ?', true, 'all')
users =
members.preload(:principal).select do |m|
m.principal.present? &&
(m.mail_notification? || m.principal.mail_notification == 'all')
end
users.collect {|m| m.principal}
end end
# Returns a scope of all custom fields enabled for project issues # Returns a scope of all custom fields enabled for project issues