From 0c60ad7acd74737e8c59fb8a6bd60a0a2551c2e5 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 13 Aug 2023 08:15:22 +0200 Subject: [PATCH] feat: Add option to not cache users in memory when requesting all of a room --- lib/src/room.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 1532850d..2596fcea 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1535,13 +1535,16 @@ class Room { /// List `membershipFilter` defines with what membership do you want the /// participants, default set to /// [[Membership.join, Membership.invite, Membership.knock]] + /// Set [cache] to `false` if you do not want to cache the users in memory + /// for this session which is highly recommended for large public rooms. Future> requestParticipants( [List membershipFilter = const [ Membership.join, Membership.invite, Membership.knock, ], - bool suppressWarning = false]) async { + bool suppressWarning = false, + bool cache = true]) async { if (!participantListComplete && partial) { // we aren't fully loaded, maybe the users are in the database final users = await client.database?.getUsers(this) ?? []; @@ -1557,7 +1560,7 @@ class Room { } final memberCount = summary.mJoinedMemberCount; - if (!suppressWarning && memberCount != null && memberCount > 100) { + if (!suppressWarning && cache && memberCount != null && memberCount > 100) { Logs().w(''' Loading a list of $memberCount participants for the room $id. This may affect the performance. Please make sure to not unnecessary @@ -1570,10 +1573,14 @@ class Room { ?.map((e) => Event.fromMatrixEvent(e, this).asUser) .toList() ?? []; - for (final user in users) { - setState(user); // at *least* cache this in-memory + + if (cache) { + for (final user in users) { + setState(user); // at *least* cache this in-memory + } } - _requestedParticipants = true; + + _requestedParticipants = cache; users.removeWhere((u) => !membershipFilter.contains(u.membership)); return users; }