diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-12-04 15:45:43 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-12-04 15:45:43 +0000 |
commit | 65b7a7a0632280c77de1dc9d6c93dfb5df0c2fc9 (patch) | |
tree | b86d2e81c4d550d89906654d5bd378b93d5654d0 /app/models | |
parent | 6a27f9b1b234470a994b0b43460bd9c8097ae12f (diff) | |
parent | 264171f72d4ef3e5dfafaf32d3d267ab279469e1 (diff) | |
download | gitlab-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')
-rw-r--r-- | app/models/group.rb | 8 | ||||
-rw-r--r-- | app/models/project.rb | 6 | ||||
-rw-r--r-- | app/models/user.rb | 6 |
3 files changed, 18 insertions, 2 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index 76262acf50c..27287f079a4 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -289,6 +289,14 @@ class Group < Namespace "#{parent.full_path}/#{path_was}" end + def group_member(user) + if group_members.loaded? + group_members.find { |gm| gm.user_id == user.id } + else + group_members.find_by(user_id: user) + end + end + private def update_two_factor_requirement diff --git a/app/models/project.rb b/app/models/project.rb index f9c82029912..0a7e7617d9b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1113,7 +1113,11 @@ class Project < ActiveRecord::Base end def project_member(user) - project_members.find_by(user_id: user) + if project_members.loaded? + project_members.find { |member| member.user_id == user.id } + else + project_members.find_by(user_id: user) + end end def default_branch 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 |