From 2f0540011307e3ea5ae569798c7f7c9b6ff226cb Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 23 Aug 2023 19:59:21 +0300 Subject: [PATCH] Dispatch updates to the UI later only after processing all of them instead of after each one --- .../RoomSummary/RoomSummaryProvider.swift | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index de49a5c92..e61b5b7b6 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -133,35 +133,41 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { MXLog.verbose("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })") + var updatedItems = rooms 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[.. [RoomSummary] { + guard let collectionDiff = buildDiff(from: diff, on: currentItems) else { MXLog.error("\(name): Failed building CollectionDifference from \(diff)") - return + return currentItems } - guard let updatedItems = rooms.applying(collectionDiff) else { + guard let updatedItems = currentItems.applying(collectionDiff) else { MXLog.error("\(name): Failed applying diff: \(collectionDiff)") - return + return currentItems } - rooms = updatedItems + return updatedItems } private func fetchRoomInfo(roomListItem: RoomListItemProtocol) -> RoomInfo? {