Defer fetching user profiles for events

Previously, events for which the sender, target (state_key) or remover
was missing from the room members would have their profile fetched
from network when registering the event into models.

This could cause very slow past events loading times for rooms, since
the event registering function (which contained the profile retrieval
directives) is run sequentially event-by-event.

Missing profiles are now lazy-loaded when events come into the
user's view in the QML timeline.
This commit is contained in:
miruka
2020-05-20 03:42:40 -04:00
parent bc5549195b
commit 63af4be1e2
6 changed files with 87 additions and 32 deletions

View File

@@ -221,10 +221,10 @@ class Backend:
async def get_profile(self, user_id: str) -> nio.ProfileGetResponse:
"""Cache and return the matrix profile of `user_id`."""
if user_id in self.profile_cache:
return self.profile_cache[user_id]
async with self.get_profile_locks[user_id]:
if user_id in self.profile_cache:
return self.profile_cache[user_id]
client = await self.get_any_client()
response = await client.get_profile(user_id)