From dcdb0b60f3bd032aae1e82f63ee44f85bce8441a Mon Sep 17 00:00:00 2001 From: 7w1 Date: Thu, 16 Jul 2026 14:29:04 -0500 Subject: [PATCH] improve the caching i think --- src/client/slidingSync.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/client/slidingSync.ts b/src/client/slidingSync.ts index b18d3b3b0..fe71244dc 100644 --- a/src/client/slidingSync.ts +++ b/src/client/slidingSync.ts @@ -219,6 +219,8 @@ export class SlidingSyncManager { private sidebarCacheReconciled = false; + private sidebarCacheReconciliationQueued = false; + private readonly serverMembershipRoomIds = new Set(); private initialSyncCompleted = false; @@ -528,20 +530,25 @@ export class SlidingSyncManager { } private reconcileSidebarCacheMembership(): void { - if (this.sidebarCacheReconciled) return; - this.sidebarCacheReconciled = true; + if (this.sidebarCacheReconciled || this.sidebarCacheReconciliationQueued) return; + this.sidebarCacheReconciliationQueued = true; - const removedRoomIds = this.sidebarCache.reconcileRooms(this.serverMembershipRoomIds); - removedRoomIds.forEach((roomId) => { - this.mx.getRoom(roomId)?.updateMyMembership(KnownMembership.Leave); - this.unsubscribeFromRoom(roomId); - }); + void this.cacheHydrationPromise.then(() => { + if (this.disposed || this.sidebarCacheReconciled) return; + this.sidebarCacheReconciled = true; - if (removedRoomIds.length > 0) { - debugLog.info('sync', 'Removed stale rooms from the sliding sync sidebar cache', { - removedRoomCount: removedRoomIds.length, + const removedRoomIds = this.sidebarCache.reconcileRooms(this.serverMembershipRoomIds); + removedRoomIds.forEach((roomId) => { + this.mx.getRoom(roomId)?.updateMyMembership(KnownMembership.Leave); + this.unsubscribeFromRoom(roomId); }); - } + + if (removedRoomIds.length > 0) { + debugLog.info('sync', 'Removed stale rooms from the sliding sync sidebar cache', { + removedRoomCount: removedRoomIds.length, + }); + } + }); } public getDiagnostics(): SlidingSyncDiagnostics {