Skip to content

Commit

Permalink
Use a single query in ProfileHandler.get_profile (matrix-org#13209)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar authored Jul 7, 2022
1 parent 4aaeb87 commit 2b5ab8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.d/13209.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce number of queries used to get profile information. Contributed by Nick @ Beeper (@fizzadar).
19 changes: 7 additions & 12 deletions synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,14 @@ async def get_profile(self, user_id: str) -> JsonDict:
target_user = UserID.from_string(user_id)

if self.hs.is_mine(target_user):
try:
displayname = await self.store.get_profile_displayname(
target_user.localpart
)
avatar_url = await self.store.get_profile_avatar_url(
target_user.localpart
)
except StoreError as e:
if e.code == 404:
raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)
raise
profileinfo = await self.store.get_profileinfo(target_user.localpart)
if profileinfo.display_name is None:
raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)

return {"displayname": displayname, "avatar_url": avatar_url}
return {
"displayname": profileinfo.display_name,
"avatar_url": profileinfo.avatar_url,
}
else:
try:
result = await self.federation.make_query(
Expand Down

0 comments on commit 2b5ab8e

Please sign in to comment.