From 55cbbc54978ae778bee3ec564df7153210ae4e14 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 22 Aug 2023 15:23:28 +0300 Subject: [PATCH] Split incoming large .resets into a reset + append in order to quicker update the UI --- .../RoomSummary/RoomSummaryProvider.swift | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 749c3eb67..6e439a898 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -133,25 +133,36 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { MXLog.info("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })") - rooms = diffs - .reduce(rooms) { currentItems, diff in - guard let collectionDiff = buildDiff(from: diff, on: currentItems) else { - MXLog.error("\(name): Failed building CollectionDifference from \(diff)") - return currentItems - } - - guard let updatedItems = currentItems.applying(collectionDiff) else { - MXLog.error("\(name): Failed applying diff: \(collectionDiff)") - return currentItems - } - - return updatedItems + for diff in diffs { + // Special case resets in order to prevent large updates from blocking the UI + // Render the first resetDiffChunkingThreshhold as a reset and then append the rest to give the UI time to update + let resetDiffChunkingThreshhold = 50 + if case .reset(let values) = diff, values.count > resetDiffChunkingThreshhold { + processDiff(RoomListEntriesUpdate.reset(values: Array(values[.. RoomInfo? { class FetchResult {