summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-12-04 15:45:43 +0000
committerDouwe Maan <douwe@gitlab.com>2017-12-04 15:45:43 +0000
commit65b7a7a0632280c77de1dc9d6c93dfb5df0c2fc9 (patch)
treeb86d2e81c4d550d89906654d5bd378b93d5654d0 /app/models/user.rb
parent6a27f9b1b234470a994b0b43460bd9c8097ae12f (diff)
parent264171f72d4ef3e5dfafaf32d3d267ab279469e1 (diff)
downloadgitlab-ce-65b7a7a0632280c77de1dc9d6c93dfb5df0c2fc9.tar.gz
Merge branch 'sh-optimize-groups-api' into 'master'
Optimize API /groups/:id/projects by preloading assocations Closes #40308 See merge request gitlab-org/gitlab-ce!15475
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 5e7fe01c825..76fd395be9a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1002,7 +1002,11 @@ class User < ActiveRecord::Base
end
def notification_settings_for(source)
- notification_settings.find_or_initialize_by(source: source)
+ if notification_settings.loaded?
+ notification_settings.find { |notification| notification.source == source }
+ else
+ notification_settings.find_or_initialize_by(source: source)
+ end
end
# Lazy load global notification setting