Commit b9c12be5 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Don't preload all memberships for a user

parent 6f5a2276
...@@ -1073,15 +1073,6 @@ class User < ActiveRecord::Base ...@@ -1073,15 +1073,6 @@ class User < ActiveRecord::Base
super super
end 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 protected
# override, from Devise::Validatable # override, from Devise::Validatable
......
...@@ -72,7 +72,7 @@ class GroupChildEntity < Grape::Entity ...@@ -72,7 +72,7 @@ class GroupChildEntity < Grape::Entity
def membership def membership
return unless request.current_user return unless request.current_user
@membership ||= request.current_user.membership_for_object(object) @membership ||= request.current_user.members.find_by(source: object)
end end
def project? def project?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment