Skip to content

feat(slidingSync): prefetch recently-visited rooms on sync complete#873

Open
Just-Insane wants to merge 5 commits into
SableClient:devfrom
Just-Insane:feat/sliding-sync-prefetch
Open

feat(slidingSync): prefetch recently-visited rooms on sync complete#873
Just-Insane wants to merge 5 commits into
SableClient:devfrom
Just-Insane:feat/sliding-sync-prefetch

Conversation

@Just-Insane
Copy link
Copy Markdown
Contributor

@Just-Insane Just-Insane commented May 19, 2026

Description

After each successful sliding sync, kick off a background prefetch for the most recently visited rooms that are not already covered by the active subscription window. Reduces the latency of navigating back to a recently open room. Includes timeline-reset detection (overlap check) to avoid redundant prefetches.

Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Fully AI generated (explain what all the generated code does in moderate detail).
  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).

After each SlidingSyncEvent.Complete, a hook compares the list of recently visited room IDs (stored in a capped LRU) against the rooms already covered by the active sliding sync subscription range. For rooms not in the window, it calls client.paginateEventTimeline with a small page limit to warm the in-memory timeline. Before prefetching, it checks canPaginateBackwards and whether the stored pagination token matches the current one to skip rooms whose timeline was reset by a sync gap.

Tracks room visits in localStorage (max 10 per user) and subscribes to top 5 most recent rooms immediately after initial sync completes. Reduces perceived navigation latency by warming the cache for likely next-room-to-be-opened scenarios.

New utilities:
- getRecentRoomIds() - retrieve recent rooms for user
- addRecentRoom() - track room visit (LRU order)
- clearRecentRooms() - cleanup on logout

Implementation:
- SlidingSyncManager.prefetchRecentRooms() called after initialSyncCompleted
- useSlidingSyncActiveRoom() tracks visits automatically
- Only subscribes if room exists and not already subscribed

Performance impact:
- Top 5 recent rooms load faster on navigation
- No-op for rooms already subscribed
- Minimal overhead (localStorage read once per sync cycle)
The >>>>>>> end-marker from commit 5406e00 was left without its
corresponding <<<<<<< / ======= markers, causing TS1185, lint, build,
and test failures.
@Just-Insane Just-Insane marked this pull request as ready for review May 19, 2026 23:16
@Just-Insane Just-Insane requested review from 7w1 and hazre as code owners May 19, 2026 23:16
Copilot AI review requested due to automatic review settings May 19, 2026 23:16

This comment was marked as spam.

…tRoomIds

Copilot review: add Array.isArray + string entry validation so
malformed or tampered localStorage data cannot cause type errors or
pass non-string values downstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants