mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Split incoming large .resets into a reset + append in order to quicker update the UI
This commit is contained in:
committed by
Stefan Ceriu
parent
4c33d9a414
commit
7b9f6d253e
@@ -133,19 +133,16 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
|||||||
|
|
||||||
MXLog.info("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
MXLog.info("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
||||||
|
|
||||||
rooms = diffs
|
for diff in diffs {
|
||||||
.reduce(rooms) { currentItems, diff in
|
// Special case resets in order to prevent large updates from blocking the UI
|
||||||
guard let collectionDiff = buildDiff(from: diff, on: currentItems) else {
|
// Render the first resetDiffChunkingThreshhold as a reset and then append the rest to give the UI time to update
|
||||||
MXLog.error("\(name): Failed building CollectionDifference from \(diff)")
|
let resetDiffChunkingThreshhold = 50
|
||||||
return currentItems
|
if case .reset(let values) = diff, values.count > resetDiffChunkingThreshhold {
|
||||||
|
processDiff(RoomListEntriesUpdate.reset(values: Array(values[..<resetDiffChunkingThreshhold])))
|
||||||
|
processDiff(RoomListEntriesUpdate.append(values: Array(values.dropFirst(resetDiffChunkingThreshhold))))
|
||||||
|
} else {
|
||||||
|
processDiff(diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let updatedItems = currentItems.applying(collectionDiff) else {
|
|
||||||
MXLog.error("\(name): Failed applying diff: \(collectionDiff)")
|
|
||||||
return currentItems
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedItems
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detectDuplicatesInRoomList(rooms)
|
detectDuplicatesInRoomList(rooms)
|
||||||
@@ -153,6 +150,20 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
|||||||
MXLog.info("\(name): Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
MXLog.info("\(name): Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func processDiff(_ diff: RoomListEntriesUpdate) {
|
||||||
|
guard let collectionDiff = buildDiff(from: diff, on: rooms) else {
|
||||||
|
MXLog.error("\(name): Failed building CollectionDifference from \(diff)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let updatedItems = rooms.applying(collectionDiff) else {
|
||||||
|
MXLog.error("\(name): Failed applying diff: \(collectionDiff)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rooms = updatedItems
|
||||||
|
}
|
||||||
|
|
||||||
private func fetchRoomInfo(roomListItem: RoomListItemProtocol) -> RoomInfo? {
|
private func fetchRoomInfo(roomListItem: RoomListItemProtocol) -> RoomInfo? {
|
||||||
class FetchResult {
|
class FetchResult {
|
||||||
var roomInfo: RoomInfo?
|
var roomInfo: RoomInfo?
|
||||||
|
|||||||
Reference in New Issue
Block a user