diff options
Diffstat (limited to 'app/finders/user_group_notification_settings_finder.rb')
-rw-r--r-- | app/finders/user_group_notification_settings_finder.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/finders/user_group_notification_settings_finder.rb b/app/finders/user_group_notification_settings_finder.rb index a6f6769116f..4ad9d1d7bf4 100644 --- a/app/finders/user_group_notification_settings_finder.rb +++ b/app/finders/user_group_notification_settings_finder.rb @@ -14,6 +14,8 @@ class UserGroupNotificationSettingsFinder @loaded_groups_with_ancestors = groups_with_ancestors.index_by(&:id) @loaded_notification_settings = user.notification_settings_for_groups(groups_with_ancestors).preload_source_route.index_by(&:source_id) + preload_emails_disabled + groups.map do |group| find_notification_setting_for(group) end @@ -45,4 +47,19 @@ class UserGroupNotificationSettingsFinder parent_setting.level != NotificationSetting.levels[:global] || parent_setting.notification_email.present? end + + # This method preloads the `emails_disabled` strong memoized method for the given groups. + # + # For each group, look up the ancestor hierarchy and look for any group where emails_disabled is true. + # The lookup is implemented with an EXISTS subquery, so we can look up the ancestor chain for each group individually. + # The query will return groups where at least one ancestor has the `emails_disabled` set to true. + # + # After the query, we set the instance variable. + def preload_emails_disabled + group_ids_with_disabled_email = Group.ids_with_disabled_email(groups.to_a) + + groups.each do |group| + group.emails_disabled_memoized = group_ids_with_disabled_email.include?(group.id) if group.parent_id + end + end end |