Don't preload all memberships for a user
This commit is contained in:
parent
6f5a2276d7
commit
b9c12be5b9
2 changed files with 1 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue