diff options
author | Wei-Meng Lee <wlee@gitlab.com> | 2019-04-26 23:33:29 +0800 |
---|---|---|
committer | Wei-Meng Lee <wlee@gitlab.com> | 2019-05-31 20:49:27 +0800 |
commit | f72383066d9758988706e697c26ba35efe90c564 (patch) | |
tree | 7697b45a93705cf3ad59a7eaa2a233890df48c24 | |
parent | 03e08ab775312b92440caadc06a88b6f6805bc18 (diff) | |
download | gitlab-ce-f72383066d9758988706e697c26ba35efe90c564.tar.gz |
Simplify logic using new group notification settings method
-rw-r--r-- | app/models/notification_recipient.rb | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb index 6889e0d776b..6f057f79ef6 100644 --- a/app/models/notification_recipient.rb +++ b/app/models/notification_recipient.rb @@ -156,23 +156,11 @@ class NotificationRecipient # Returns the notification_setting of the lowest group in hierarchy with non global level def closest_non_global_group_notification_settting return unless @group - return if indexed_group_notification_settings.empty? - notification_setting = nil - - @group.self_and_ancestors_ids.each do |id| - notification_setting = indexed_group_notification_settings[id] - break if notification_setting - end - - notification_setting - end - - def indexed_group_notification_settings - strong_memoize(:indexed_group_notification_settings) do - @group.notification_settings.where(user_id: user.id) - .where.not(level: NotificationSetting.levels[:global]) - .index_by(&:source_id) - end + @group + .notification_settings(hierarchy_order: :asc) + .where(user: user) + .where.not(level: NotificationSetting.levels[:global]) + .first end end |