diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 16:25:26 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-10 16:55:03 +0200 |
commit | b9c12be5b932245a0c7e77b953c20ef379f0ef94 (patch) | |
tree | 0c801b336ff53a75e91fb297b2db15ef13e59243 | |
parent | 6f5a2276d77dc556bebb39c5992a6fd16ed376be (diff) | |
download | gitlab-ce-b9c12be5b932245a0c7e77b953c20ef379f0ef94.tar.gz |
Don't preload all memberships for a user
-rw-r--r-- | app/models/user.rb | 9 | ||||
-rw-r--r-- | app/serializers/group_child_entity.rb | 2 |
2 files changed, 1 insertions, 10 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 8ce0fecc34d..4e71a3e11c2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1073,15 +1073,6 @@ class User < ActiveRecord::Base super end - # Get the membership for an object without loading the source of the membership - # - # This loads the entire `members` relation of the user, used on `current_user` - def membership_for_object(object) - members.sort('access_level_asc').detect do |member| - object.is_a?(member.source_type.constantize) && member.source_id == object.id - end - end - protected # override, from Devise::Validatable diff --git a/app/serializers/group_child_entity.rb b/app/serializers/group_child_entity.rb index 2f24ca9c4db..5c1fa72b1ac 100644 --- a/app/serializers/group_child_entity.rb +++ b/app/serializers/group_child_entity.rb @@ -72,7 +72,7 @@ class GroupChildEntity < Grape::Entity def membership return unless request.current_user - @membership ||= request.current_user.membership_for_object(object) + @membership ||= request.current_user.members.find_by(source: object) end def project? |