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

fix: Workaround for too big sqflite tables #1652

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class Client extends MatrixApi {
this.shareKeysWithUnverifiedDevices = true,
this.enableDehydratedDevices = false,
this.receiptsPublicByDefault = true,
this.maxStoreReadReceiptsPerRoom = 100,
}) : syncFilter = syncFilter ??
Filter(
room: RoomFilter(
Expand Down Expand Up @@ -217,6 +218,13 @@ class Client extends MatrixApi {
registerDefaultCommands();
}

/// Sets a maximum amount of stored read receipts per room. Own read receipts
/// will always be excluded from this. This will stop persisting receipts
/// after the maximum is reached. For each user and thread there is one
/// read receipt stored.
/// Workaround for Workaround for https://github.com/famedly/matrix-dart-sdk/issues/1642
final int maxStoreReadReceiptsPerRoom;

/// The required name for this client.
final String clientName;

Expand Down
22 changes: 21 additions & 1 deletion lib/src/models/receipts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ class LatestReceiptState {
this.byThread = const {},
});

int get receiptCount {
var count = global.otherUsers.length;
count += (mainThread?.otherUsers.length ?? 0);
for (final thread in byThread.values) {
count += thread.otherUsers.length;
}
return count;
}

factory LatestReceiptState.fromJson(Map<String, dynamic> json) {
final global = json['global'] ?? <String, dynamic>{};
final Map<String, dynamic> main = json['main'] ?? <String, dynamic>{};
Expand Down Expand Up @@ -246,6 +255,8 @@ class LatestReceiptState {
) async {
final List<LatestReceiptStateForTimeline> updatedTimelines = [];
final ownUserid = room.client.userID!;
var count = receiptCount;
final receiptsMaxLength = room.client.maxStoreReadReceiptsPerRoom;

content.receipts.forEach((eventId, receiptsByType) {
receiptsByType.forEach((receiptType, receiptsByUser) {
Expand All @@ -271,7 +282,16 @@ class LatestReceiptState {
}
updatedTimelines.add(timeline);
} else {
timeline.otherUsers[user] = receiptData;
if (count > receiptsMaxLength) {
// Workaround for https://github.com/famedly/matrix-dart-sdk/issues/1642
Logs().w(
'Reached maximum amount of storable read receipts',
receiptsMaxLength,
);
} else {
count++;
timeline.otherUsers[user] = receiptData;
}
}
});
});
Expand Down