From e07bcf1184c8790e40a8a2e376aedde7670e256d Mon Sep 17 00:00:00 2001 From: Drake Harper Date: Mon, 3 Jun 2024 15:35:54 -0600 Subject: [PATCH] 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 Reviewed-by: Spencer Olson QA-Review: Drake Harper Product-Review: Drake Harper --- app/graphql/types/user_type.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb index 55cdd3a15d2..1176a9f7f42 100644 --- a/app/graphql/types/user_type.rb +++ b/app/graphql/types/user_type.rb @@ -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