Expand description
Per-account RAM cache for Community sync state.
Consolidates what were three scattered LazyLock statics (oldest-page cursor, history-start
floors, in-flight page de-dup) into ONE structure under ONE invalidation key: the session
generation. Any access after an account swap — which bumps current_session_generation() —
transparently resets the cache, so stale per-channel state can never bleed into the next
account. Holds the page cursors (oldest back-paging floor + newest since floor), history-start
flags, and in-flight page de-dup; future RAM-cache work (e.g. invite preload) layers onto the
same structure + invalidation discipline.
Functions§
- abort_
preload - The warm-up fetch failed/was cancelled — drop the entry so an adopter falls back immediately.
- advance_
newest_ cursor - Advance the latest-page
sincefloor to the newest wire time this page returned (monotonic — only ever steps forward). Call ONLY for latest-page fetches. - advance_
oldest_ cursor - Advance the back-paging cursor to the oldest wire time this page returned (monotonic — only ever steps further back).
- begin_
preload - Mark a community’s warm-up as in-flight (so a racing Join adopts it rather than double-fetching). Evicts stale/cross-generation entries and, if over the cap, the oldest.
- clear
- Drop all cached state (account swap / reset). Access-time generation checks self-reset too, so this is an explicit belt-and-suspenders teardown.
- clear_
channel_ floors - Clear a channel’s back-paging floors (history-start + oldest cursor) — e.g. after a multi-epoch backfill makes older history reachable again.
- clear_
channel_ sync_ state - Drop ALL of a channel’s sync state (floors + the latest-page
sincecursor) — community teardown. A survivingsincecursor makes a same-session REJOIN sync “since I left” instead of cold, so the rejoined chat opens empty despite plenty of history. - end_
page_ fetch - Release an in-flight page-fetch claim (success or error).
- finish_
preload - The warm-up fetch landed — make its page available to promote/adopt.
- is_
at_ history_ start - Has the channel’s network history-start been reached? Older pages then stay DB-only.
- mark_
history_ start - Mark the channel as having reached its network history-start.
- newest_
cursor - Newest OUTER created_at (seconds) seen on a latest page for the channel — the
sincefloor for the next latest fetch.Nonebefore the first latest fetch this session (→ full newest page). - oldest_
cursor - Oldest OUTER created_at (seconds) fetched for the channel — the back-paging cursor.
- take_
or_ await_ preload - Adopt a community’s warm-up as this sync’s page: Ready → take it; Pending → await it (the
in-flight fetch IS the page, so this waits only the request’s remaining time, never firing a
second); absent/stale/failed →
Noneso the caller fetches normally. Polls at coarse granularity (imperceptible vs. a fresh round-trip) to stay free of notification races. - take_
ready_ preload - Non-blocking take for promotion at Accept: returns the page ONLY if already Ready, leaving a
still-Pending warm-up in place for the sync to adopt.
Noneif absent / Pending / stale. - try_
begin_ page_ fetch - Claim an in-flight page fetch (key
"{channel_id}:{older|latest}"). Returnsfalseif one is already running — the caller should no-op. Pair withend_page_fetch.