From bf2561f937c3e62561ecd756cd62103d0518e1b9 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 18 Aug 2026 12:52:47 +0300 Subject: [PATCH] Delay secondary room summary provider setup (#6038) To avoid creating room summaries for them on startup, especially as the static one uses a page size as big as the whole account. --- .../Sources/Services/Client/ClientProxy.swift | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index d86c67093..594434639 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -1563,7 +1563,6 @@ private struct ClientProxyServices { name: "AlternateAllRooms", notificationSettings: notificationSettings, appSettings: appSettings) - try await alternateRoomSummaryProvider.setRoomList(roomListService.allRooms()) staticRoomSummaryProvider = RoomSummaryProvider(roomListService: roomListService, eventStringBuilder: eventStringBuilder, @@ -1571,7 +1570,29 @@ private struct ClientProxyServices { roomListPageSize: .max, notificationSettings: notificationSettings, appSettings: appSettings) - try await staticRoomSummaryProvider.setRoomList(roomListService.allRooms()) + + // Setting a provider's room list will create summaries for every room so + // wait until the app is fully running for the alternate and static providers. + Task { [roomSummaryProvider, alternateRoomSummaryProvider, staticRoomSummaryProvider] in + // Wait for actual content (or a loaded-but-empty account) as the loading state + // doesn't take into account the app having build and published any summaries. + for await rooms in roomSummaryProvider.roomListPublisher.values { + if !rooms.isEmpty { + break + } + + if case .loaded(0) = roomSummaryProvider.statePublisher.value { + break + } + } + + do { + try await alternateRoomSummaryProvider.setRoomList(roomListService.allRooms()) + try await staticRoomSummaryProvider.setRoomList(roomListService.allRooms()) + } catch { + fatalError("Failed setting up the deferred room summary providers: \(error)") + } + } self.syncService = syncService self.roomListService = roomListService