summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-10 16:25:26 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-10 16:55:03 +0200
commitb9c12be5b932245a0c7e77b953c20ef379f0ef94 (patch)
tree0c801b336ff53a75e91fb297b2db15ef13e59243
parent6f5a2276d77dc556bebb39c5992a6fd16ed376be (diff)
downloadgitlab-ce-b9c12be5b932245a0c7e77b953c20ef379f0ef94.tar.gz
Don't preload all memberships for a user
-rw-r--r--app/models/user.rb9
-rw-r--r--app/serializers/group_child_entity.rb2
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?