Patch #23328

Updated by Go MAEDA over 7 years ago

Hi guys, 
 When Redmine look for what members it should send e-mail, they interate one by one fetching principal. 
 This is a N + 1 Query problem. 

 When we have more then 5K users in one project it is a problem. So with a single line change I drop the time for update issue from 5 to 2 seconds. 

 I hope this help you. 

 <pre><code class="diff"< ''' 
 commit 619e156986dde1b674fa1e56bad4bc862c6e9df3 
 Author: Victor Campos <> 
 Date:     Tue Jul 12 19:37:14 2016 -0300 

     improve update/create speed 

 diff --git a/app/models/project.rb b/app/models/project.rb 
 index 660a486..88bd8eb 100644 
 --- a/app/models/project.rb 
 +++ b/app/models/project.rb 
 @@ -524,7 +524,7 @@ class Project < ActiveRecord::Base 
    # Returns the users that should be notified on project events 
    def notified_users 
      # TODO: User part should be extracted to User#notify_about? 
 - {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} 
 +      members.includes(:principal).select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} 
    # Returns a scope of all custom fields enabled for project issues 
 </code></pre> '''