Fix pseudonym n+1 in gql user.avatar_url

flag=none

Test Plan:
- before pulling code
- turn on Prosopite (doc/detect_n_plus_one_queries.md)
- find a page that loads user.avatar_url n+1 via gql (ie sg2)
- pull code
- reload the page
 > should not see n+1

Change-Id: If1937f2cd154c1e54adddce55ba50b16351907cf
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/349078
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Spencer Olson <solson@instructure.com>
QA-Review: Drake Harper <drake.harper@instructure.com>
Product-Review: Drake Harper <drake.harper@instructure.com>
This commit is contained in:
Drake Harper 2024-06-03 15:35:54 -06:00
parent 877f359896
commit e07bcf1184
1 changed files with 6 additions and 4 deletions

View File

@ -59,10 +59,12 @@ module Types
field :avatar_url, UrlType, null: true
def avatar_url
if object.account.service_enabled?(:avatars)
AvatarHelper.avatar_url_for_user(object, context[:request], use_fallback: false)
else
nil
Loaders::AssociationLoader.for(User, :pseudonym).load(object).then do
if object.account.service_enabled?(:avatars)
AvatarHelper.avatar_url_for_user(object, context[:request], use_fallback: false)
else
nil
end
end
end