Avoid re-applying identical room list filters

The home screen's filter observation fires on every view state change, so setFilter was repeatedly pushing the same filter down into the SDK. Cache the last applied filter and skip the SDK call when it hasn't changed.
This commit is contained in:
Stefan Ceriu
2026-08-12 17:19:13 +03:00
parent 5cb4a2fe5a
commit df6b7d0d21
@@ -27,6 +27,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private var cancellables = Set<AnyCancellable>()
private var listUpdatesSubscriptionResult: RoomListEntriesWithDynamicAdaptersResult?
private var currentFilter: RoomSummaryProviderFilter?
private var stateUpdatesTaskHandle: TaskHandle?
private let roomListSubject = CurrentValueSubject<[RoomSummary], Never>([])
@@ -117,6 +118,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
})
// Forces the listener above to be called with the current state
currentFilter = nil
setFilter(.all(filters: []))
let stateUpdatesSubscriptionResult = try roomList.loadingState(listener: SDKListener { [loadingStateContinuation] state in
@@ -136,6 +138,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
}
func setFilter(_ filter: RoomSummaryProviderFilter) {
guard filter != currentFilter else {
return
}
currentFilter = filter
let baseFilter: [RoomListEntriesDynamicFilterKind] = [.any(filters: [.all(filters: [.nonSpace, .nonLeft]),
.all(filters: [.space, .invite])]),
.deduplicateVersions]