diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-08-01 04:56:56 +0300 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-08-03 19:07:18 +0300 |
commit | 488e8e79dd85e973e1b562fe0320f69b2bedec06 (patch) | |
tree | 71982624cf3330c04ae1641b1d963efd855e69d9 /app/services | |
parent | 3c56e41402301f26bf70afe13d2565e74e4427eb (diff) |
force queries to include notification settings
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/notification_recipient_service.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/services/notification_recipient_service.rb b/app/services/notification_recipient_service.rb index 7c9bb54f020..1ce92c8cbdc 100644 --- a/app/services/notification_recipient_service.rb +++ b/app/services/notification_recipient_service.rb @@ -50,11 +50,20 @@ module NotificationRecipientService def <<(arg) users, type = arg + + if users.is_a?(ActiveRecord::Relation) + users = users.includes(:notification_settings) + end + users = Array(users) users.compact! recipients.concat(users.map { |u| make_recipient(u, type) }) end + def user_scope + User.includes(:notification_settings) + end + def make_recipient(user, type) NotificationRecipient.new( user, type, @@ -114,7 +123,7 @@ module NotificationRecipientService global_users_ids = user_ids_with_project_level_global.concat(user_ids_with_group_level_global) user_ids += user_ids_with_global_level_custom(global_users_ids, custom_action) - self << [User.find(user_ids), :watch] + self << [user_scope.where(id: user_ids), :watch] end def add_project_watchers @@ -133,7 +142,7 @@ module NotificationRecipientService user_ids_with_project_setting = select_project_members_ids(project, user_ids_with_project_global, user_ids) user_ids_with_group_setting = select_group_members_ids(project.group, project_members_ids, user_ids_with_group_global, user_ids) - User.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq).to_a + user_scope.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq) end def add_subscribed_users |