Skip to content
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

Limit concurrent HTTP requests #1898

Merged
merged 18 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
466 changes: 55 additions & 411 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,57 @@ default-members = ["native/acter"]

[workspace.dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/crates/matrix-sdk"
default-features = false
features = ["experimental-sliding-sync"]

[workspace.dependencies.matrix-sdk-base]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/crates/matrix-sdk-base"
default-features = false

[workspace.dependencies.matrix-sdk-sqlite]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/crates/matrix-sdk-sqlite"
default-features = false
features = ["crypto-store", "state-store"]

[workspace.dependencies.matrix-sdk-store-encryption]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/crates/matrix-sdk-store-encryption"
default-features = false

[workspace.dependencies.matrix-sdk-test]
[workspace.dependencies.matrix-sdk-ui]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/crates/matrix-sdk-ui"
default-features = false
features = ["e2e-encryption"]

[workspace.dependencies.matrix-sdk-ui]
[workspace.dependencies.matrix-sdk-test]
git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "1380af4f005ee5f34607db5cbb6705f93048b85a"
# path = "../matrix-rust-sdk/testing/matrix-sdk-test"
default-features = false
features = ["e2e-encryption"]

[workspace.dependencies.ruma]
git = "https://github.com/Hywan/ruma"
branch = "feat-sliding-sync-list-include-heroes"
git = "https://github.com/ruma/ruma"
rev = "e5a370f7e5fcebb0da6e4945e51c5fafba9aa5f0"
features = ["client-api-c", "compat-upload-signatures", "compat-user-id", "compat-arbitrary-length-ids", "unstable-msc3401"]

[workspace.dependencies.ruma-client-api]
git = "https://github.com/Hywan/ruma"
branch = "feat-sliding-sync-list-include-heroes"
git = "https://github.com/ruma/ruma"
rev = "e5a370f7e5fcebb0da6e4945e51c5fafba9aa5f0"

[workspace.dependencies.ruma-common]
git = "https://github.com/Hywan/ruma"
branch = "feat-sliding-sync-list-include-heroes"
git = "https://github.com/ruma/ruma"
rev = "e5a370f7e5fcebb0da6e4945e51c5fafba9aa5f0"

[workspace.dependencies.ruma-events]
git = "https://github.com/Hywan/ruma"
branch = "feat-sliding-sync-list-include-heroes"
git = "https://github.com/ruma/ruma"
rev = "e5a370f7e5fcebb0da6e4945e51c5fafba9aa5f0"

[workspace.dependencies.ruma-macros]
git = "https://github.com/Hywan/ruma"
branch = "feat-sliding-sync-list-include-heroes"
git = "https://github.com/ruma/ruma"
rev = "e5a370f7e5fcebb0da6e4945e51c5fafba9aa5f0"

[workspace.dependencies.url]
version = "2.5.0"
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/providers/notifiers/room_notifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AsyncMaybeRoomNotifier extends FamilyAsyncNotifier<Room?, String> {
try {
return await client.room(arg);
} catch (e) {
_log.warning('room not found', e);
_log.warning('room $arg not found', e);
return null;
}
}
Expand Down
125 changes: 42 additions & 83 deletions app/lib/common/providers/room_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ final maybeRoomProvider =
() => AsyncMaybeRoomNotifier(),
);

/// Provider the profile data of a the given room, keeps up to date with underlying client
// final roomProfileDataProvider =
// FutureProvider.autoDispose.family<AvatarInfo, String>((ref, roomId) async {
// final room = await ref.watch(maybeRoomProvider(roomId).future);
// if (room == null) {
// throw RoomNotFound;
// }

// final profile = room.getProfile();
// OptionString displayName = await profile.getDisplayName();
// try {
// final avatar = (await profile.getAvatar(null)).data();
// _log.info('$roomId : hasAvatar: ${avatar != null}');
// return ProfileData(displayName.text(), avatar);
// } catch (error) {
// _log.severe('Loading avatar for $roomId failed', error);
// return ProfileData(displayName.text(), null);
// }
// });

/// gives current visibility state of space, return empty if no space is found
final roomVisibilityProvider = FutureProvider.family
.autoDispose<RoomVisibility?, String>((ref, roomId) async {
Expand Down Expand Up @@ -94,26 +74,6 @@ final roomInvitedMembersProvider = FutureProvider.autoDispose
return members.toList();
});

/// Get the RoomItem of the given sapceId filled in brief form
/// (only spaceProfileData, no activeMembers) with Membership.
/// Stays up to date with underlying client info
final briefRoomItemWithMembershipProvider =
FutureProvider.autoDispose.family<RoomItem, String>((ref, roomId) async {
final room = await ref.watch(maybeRoomProvider(roomId).future);
if (room == null) {
throw RoomNotFound;
}

final avatarInfo = ref.watch(roomAvatarInfoProvider(roomId));
return RoomItem(
roomId: roomId,
room: room,
membership: room.isJoined() ? await room.getMyMembership() : null,
activeMembers: [],
avatarInfo: avatarInfo,
);
});

final roomSearchValueProvider =
StateProvider.autoDispose<String?>((ref) => null);

Expand All @@ -127,13 +87,8 @@ final _briefGroupChatsWithName =
List<_RoomIdAndName> items = [];
for (final convo in chatList) {
final roomId = convo.getRoomIdStr();
final room = await ref.watch(maybeRoomProvider(roomId).future);

if (room != null) {
final profile = room.getProfile();
OptionString displayName = await profile.getDisplayName();
items.add((roomId, displayName.text()));
}
final displayName = ref.watch(roomDisplayNameProvider(roomId)).valueOrNull;
items.add((roomId, displayName));
}
return items;
});
Expand Down Expand Up @@ -197,45 +152,31 @@ final parentIdsProvider =
}
});

/// Caching the Profile of each Room
final _roomProfileProvider =
FutureProvider.family<RoomProfile, String>((ref, roomId) {
final room = ref.watch(maybeRoomProvider(roomId)).valueOrNull;
if (room == null) {
throw RoomNotFound;
}

return room.getProfile();
});

/// Caching the name of each Room
final roomDisplayNameProvider =
FutureProvider.family<String?, String>((ref, roomId) async {
try {
final profile = await ref.watch(_roomProfileProvider(roomId).future);
return (await profile.getDisplayName()).text();
} on RoomNotFound {
final room = await ref.watch(maybeRoomProvider(roomId).future);
if (room == null) {
return null;
}
return (await room.displayName()).text();
});

/// Caching the MemoryImage of each room
final roomAvatarProvider =
FutureProvider.family<MemoryImage?, String>((ref, roomId) async {
try {
final sdk = await ref.watch(sdkProvider.future);
final thumbsize = sdk.api.newThumbSize(48, 48);

final avatar = (await (await ref.watch(_roomProfileProvider(roomId).future))
.getAvatar(thumbsize))
.data();
if (avatar != null) {
return MemoryImage(avatar.asTypedList());
}
return null;
} on RoomNotFound {
final sdk = await ref.watch(sdkProvider.future);
final thumbsize = sdk.api.newThumbSize(48, 48);
final room = await ref.watch(maybeRoomProvider(roomId).future);
if (room == null || !room.hasAvatar()) {
return null;
}

final avatar = (await room.avatar(thumbsize)).data();
if (avatar != null) {
return MemoryImage(avatar.asTypedList());
}
return null;
});

/// Provide the AvatarInfo for each room. Update internally accordingly
Expand Down Expand Up @@ -338,9 +279,22 @@ final _memberProfileProvider = FutureProvider.autoDispose
return member.getProfile();
});

final membershipStatusStr =
FutureProvider.autoDispose.family<String, MemberInfo>((ref, query) async {
final member = await ref.watch(memberProvider(query).future);
return member.membershipStatusStr();
});

final memberDisplayNameProvider =
FutureProvider.autoDispose.family<String?, MemberInfo>((ref, query) async {
return ref.watch(_memberProfileProvider(query)).valueOrNull?.getDisplayName();
try {
return ref
.watch(_memberProfileProvider(query))
.valueOrNull
?.getDisplayName();
} on RoomNotFound {
return null;
}
});

/// Caching the MemoryImage of each room
Expand All @@ -349,14 +303,18 @@ final _memberAvatarProvider = FutureProvider.autoDispose
final sdk = await ref.watch(sdkProvider.future);

final thumbsize = sdk.api.newThumbSize(48, 48);
final profile = await ref.watch(_memberProfileProvider(query).future);
// use .data() consumes the value so we keep it stored, any further call to .data()
// comes back empty as the data was consumed.
final avatar = (await profile.getAvatar(thumbsize)).data();
if (avatar != null) {
return MemoryImage(avatar.asTypedList());
try {
final profile = await ref.watch(_memberProfileProvider(query).future);
// use .data() consumes the value so we keep it stored, any further call to .data()
// comes back empty as the data was consumed.
final avatar = (await profile.getAvatar(thumbsize)).data();
if (avatar != null) {
return MemoryImage(avatar.asTypedList());
}
return null;
} on RoomNotFound {
return null;
}
return null;
});

final memberAvatarInfoProvider =
Expand All @@ -371,11 +329,12 @@ final memberAvatarInfoProvider =
);
});

/// Ids of the members of this Room. Returns empty list if the room isn't found
final membersIdsProvider =
FutureProvider.family<List<String>, String>((ref, roomIdOrAlias) async {
final room = await ref.watch(maybeRoomProvider(roomIdOrAlias).future);
if (room == null) {
throw RoomNotFound;
return [];
}
final members = await room.activeMembersIds();
return asDartStringList(members);
Expand Down
6 changes: 2 additions & 4 deletions app/lib/common/providers/space_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ final _spaceIdAndNames =
final spaces = ref.watch(spacesProvider);
List<_SpaceIdAndName> items = [];
for (final space in spaces) {
final roomId = space.getRoomIdStr();
items.add(
(
space.getRoomIdStr(),
(await space.getProfile().getDisplayName()).text()
),
(roomId, await ref.watch(roomDisplayNameProvider(roomId).future)),
);
}
return items;
Expand Down
13 changes: 6 additions & 7 deletions app/lib/common/widgets/room/brief_room_list_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class BriefRoomEntry extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final roomData = ref.watch(briefRoomItemWithMembershipProvider(roomId));
final canLink = roomData.maybeWhen(
data: (roomData) => roomData.membership!.canString(canCheck),
final roomMembership = ref.watch(roomMembershipProvider(roomId));
final canLink = roomMembership.maybeWhen(
data: (membership) => membership?.canString(canCheck) == true,
orElse: () => false,
);
final roomName =
ref.watch(roomDisplayNameProvider(roomId)).valueOrNull ?? roomId;
Widget? trailing;
if (trailingBuilder != null) {
trailing = trailingBuilder!(canLink);
Expand All @@ -42,10 +44,7 @@ class BriefRoomEntry extends ConsumerWidget {
key: Key('$keyPrefix-$roomId'),
enabled: canLink,
leading: RoomAvatarBuilder(roomId: roomId, avatarSize: 24),
title: roomData.maybeWhen(
data: (roomData) => Text(roomData.avatarInfo.displayName ?? roomId),
orElse: () => Text(roomId),
),
title: Text(roomName),
subtitle: subtitle,
trailing: trailing,
onTap: canLink && onSelect != null ? () => onSelect!(roomId) : null,
Expand Down
38 changes: 17 additions & 21 deletions app/lib/common/widgets/user_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,41 @@ bool isJoined(String userId, List<String> joined) {
}

class UserBuilder extends ConsumerWidget {
final UserProfile profile;
final String userId;
final String roomId;

const UserBuilder({
super.key,
required this.profile,
required this.userId,
required this.roomId,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final room = ref.watch(briefRoomItemWithMembershipProvider(roomId));
final avatarProv = ref.watch(userAvatarProvider(profile));
final displayName = profile.getDisplayName();
final userId = profile.userId().toString();
final room = ref.watch(maybeRoomProvider(roomId)).valueOrNull;
final avatarInfo =
ref.watch(memberAvatarInfoProvider((roomId: roomId, userId: userId)));
final displayName = ref
.watch(memberDisplayNameProvider((roomId: roomId, userId: userId)))
.valueOrNull;
return Card(
child: ListTile(
title: Text(displayName ?? userId),
subtitle: (displayName == null) ? null : Text(userId),
leading: ActerAvatar(
options: AvatarOptions.DM(
AvatarInfo(
uniqueId: userId,
displayName: displayName,
avatar: avatarProv.valueOrNull,
),
avatarInfo,
size: 18,
),
),
trailing: room.when(
data: (data) => UserStateButton(
userId: userId,
room: data.room!,
),
error: (err, stackTrace) => Text('Error: $err'),
loading: () => const Skeletonizer(
child: Text('Loading user'),
),
),
trailing: room != null
? UserStateButton(
userId: userId,
room: room,
)
: const Skeletonizer(
child: Text('Loading user'),
),
),
);
}
Expand Down
Loading
Loading