From 6772f51eaa087b86360477556152a537fde7eff3 Mon Sep 17 00:00:00 2001 From: Lucas Arnaud Date: Thu, 14 Jul 2016 14:43:12 -0300 Subject: [PATCH] Improving performance of project notified_users by eager loading members principal --- app/models/project.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 9868e04..dca76e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -524,7 +524,9 @@ 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? - members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} + members.eager_load(:principal).find_each() + .select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')} + .collect {|m| m.principal} end # Returns a scope of all custom fields enabled for project issues -- 1.8.3.1