-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: lazy load global profile from db #1798
base: main
Are you sure you want to change the base?
Conversation
When using the getProfileFromUserId with getFromRooms == true, it would always fail to load any profile from the database. This is because by default rooms are partial/not postLoaded, which means no state is in memory. However we usually also don't want to load all members in all rooms just to have a usable offline behaviour. So this changes the function to first check the non-partial rooms. If none of them have the profile, it then starts looking for the specific user profile in the partial rooms. This should only load one member event, which hopefully is faster than loading all members in all rooms.
User? foundUser; | ||
// check in memory first | ||
for (final room in rooms) { | ||
if (!room.partial) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!room.partial) { | |
if (room.partial) continue; |
// check in memory first | ||
for (final room in rooms) { | ||
if (!room.partial) { | ||
foundUser = await room.requestUser(userId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does request the user from the database and even from the server but we only want to check the cache, right? So we can do this synchroniously by:
foundUser = room.getState(EventTypes.RoomMember, userId)?.asUser;
if (foundUser == null) { | ||
for (final room in rooms) { | ||
if (room.partial) { | ||
foundUser = await room.requestUser(userId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would try to request the user from server for each room which would result into 1000 failed requests if we have 1000 rooms where this user is not participating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it would not, because both requestProfile and requestState are set to false. None of these requests should be doing any server requests.
Future<User?> requestUser( | ||
String mxID, { | ||
bool ignoreErrors = false, | ||
bool requestProfile = true, | ||
bool requestState = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick but requestState
for requesting a profile from server sounds like a really confusing name for that variable. Can you make this a bit more verbose?
When using the getProfileFromUserId with getFromRooms == true, it would always fail to load any profile from the database. This is because by default rooms are partial/not postLoaded, which means no state is in memory. However we usually also don't want to load all members in all rooms just to have a usable offline behaviour.
So this changes the function to first check the non-partial rooms. If none of them have the profile, it then starts looking for the specific user profile in the partial rooms. This should only load one member event, which hopefully is faster than loading all members in all rooms.