Don't pick a random client to get user profiles

Causes problem if one of the candidate client is on a server that
doesn't federate (e.g. a local one). Move the `get_profile()` function
from Backend to MatrixClient.
This commit is contained in:
miruka
2020-08-23 16:18:54 -04:00
parent 7502c1a9b4
commit 0f2efa9ba3
2 changed files with 18 additions and 19 deletions

View File

@@ -371,22 +371,6 @@ class Backend:
# Client functions that don't need authentification
async def get_profile(
self, user_id: str, use_cache: bool = True,
) -> nio.ProfileGetResponse:
"""Cache and return the matrix profile of `user_id`."""
async with self.get_profile_locks[user_id]:
if use_cache and user_id in self.profile_cache:
return self.profile_cache[user_id]
client = self.clients.get(user_id) or await self.get_any_client()
response = await client.get_profile(user_id)
self.profile_cache[user_id] = response
return response
async def thumbnail(
self, server_name: str, media_id: str, width: int, height: int,
) -> nio.ThumbnailResponse: