mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
0dca767e5ee08d07756aed1b2cbdf6c1a91d44ef
2 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1a5c6939c5 |
perf(mobile): save the open-channel directory and catch it up (#9513)
Search and invite recovery read a community's open-channel directory (every open, listed channel's kind 39000 metadata) from the relay, and match names on the device. Until now the app kept that directory in memory for 30 seconds only, so every search session after that, and the first search after every launch, downloaded the whole directory again. This follows [#9466 directory-only search load](https://github.com/block/buzz/pull/9466) and [#9457 directory keeps message times](https://github.com/block/buzz/pull/9457), which made each of those downloads cheaper; this one makes most of them unnecessary. Now the directory is saved in a file per community and account, next to the image cache, and search reads it from there: - **What's saved.** Only the latest revision of each open, listed, non-DM channel. The relay's directory read also returns the user's own private, unlisted and DM channels; those are never held or saved as the directory, and a channel whose latest revision is no longer discoverable drops out. - **First read.** The first time search opens, the app downloads the whole directory, as before, and saves it. - **Catch-up.** When search opens later, it shows the saved copy at once. At most once a minute, it asks the relay in the background only for directory changes since the newest saved one, or since the last read started by the device clock if that is earlier (less a minute of overlap), and merges them in. The relay can stamp a busy channel's metadata minutes ahead of wall time, so the newest saved stamp alone could skip channels created meanwhile. A catch-up that brings back nothing new saves nothing and leaves the list alone, and a search opened while a background read is still running shares it rather than starting another. - **Offline open.** A search opened before the session connects shows the saved copy and runs its check on the next connect. - **Daily full read.** Once the last full read is a day old (or dated in the future, by a clock since set back), the next check downloads the whole directory in the background and replaces the saved copy, which drops channels that became private or unlisted or were deleted. A catch-up can't see those: the relay never serves them to a non-member. - **Gone on open.** Opening a saved result that the relay no longer serves (private or deleted) drops it from the directory at once, and no directory read already in flight (background check, list refresh or Retry) brings it back. A restore from disk never overrides a full read already running, and a background read never displaces one. - **Invite recovery** still downloads the whole directory, as on main: it needs fresh memberships, and its read also refreshes the saved copy. - **Cleanup.** Signing out of a community, replacing its account, or leaving it deletes the file. The saved events omit signatures (the relay signed them; the copy is a cache of what it served). The file's JSON is encoded and decoded off the UI isolate, and an unavailable caches directory (or one that takes over 3 seconds) just means no saved copy. A file that is unreadable, from another version, or over 20,000 channels or 16 MiB is discarded and read again from the relay. There is no relay change. `CONTEXT.md` gains an "Open-channel directory" entry. ### Validation | Workflow (small community, 63 open channels) | Directory bytes before | Directory bytes after | | --- | --- | --- | | First search after install | 39.5 KB (2 requests) | 39.5 KB (2 requests) | | Search again 2 minutes later | 39.5 KB (2 requests) | 0.6 KB (2 requests) | | Relaunch, then search | 39.5 KB (2 requests) | 0.6 KB (2 requests) | Measured on an iOS simulator signed in to a test community, with a temporary local counter on each relay query response (not part of this PR), main at [ |
||
|
|
ab73cd9fb5 |
perf(mobile): restore cached channels before community sync (#8580)
## Summary Returning to a previously visited community shows its saved channel list immediately, including offline, while membership and unread state refresh in the background. Initial revalidation failures keep the list visible and retry every 60 seconds without overlapping background attempts. After successful history revalidation, ordinary reconnects use metadata-only refreshes. A reconnect arriving during a background request queues one follow-up attempt; timer ticks never queue overlapping work. History deadlines retain the full-revalidation retry until history succeeds. Snapshots are disposable, versioned and scoped by canonical relay URL and signing identity, capped at 2 MB / 2,000 member channels. They include hidden-DM IDs and prefer fresher in-memory state. Community removal and identity replacement retire outstanding writes; re-adding unchanged credentials preserves the current cache and writer. Startup sweeps orphan snapshots without waiting for disk acknowledgement; community mutations also sweep orphan snapshots, including data restored without secure community records. Cache-delete failures do not block sign-out or strand push revocation; deletion is attempted before journaling and retried by orphan cleanup. Successfully persisted unchanged snapshots skip disk writes; failed writes remain retryable. The cold path reuses fetched membership rosters, overlaps profile/latest-message requests, shares verified DM profiles with avatars, and fetches the own profile once per authenticated connection. Community connection work overlaps the switching animation; avatar hydration no longer gates landing. Full channel refreshes also revalidate cached DM participant profiles so relay-side name changes reach labels and avatars; metadata-only reconnects and background refreshes reuse admitted profiles. Me-chat and invite starter recovery use an explicit fresh membership fetch that propagates errors while leaving the cached list visible. Cached layout/read preferences permit immediate landing; newer cross-device preferences may update ordering or badges after reveal. Integrated with main’s #8490 idle/resume changes: hidden chats detach live subscriptions, background membership polling stays quiet, and each resume reconciles once. Chat history follows main’s live-admission-first ordering to avoid missing messages committed during relay admission; cached community landing remains immediate. ## Validation - `just mobile-install mobile-check mobile-test`: clean analysis; 3,778 tests passed, 19 skipped; four checks for builds without push configuration passed. File-size and diff checks passed. - Provider/storage journeys cover offline startup, failed initial revalidation recovering live delivery, bounded retries, lightweight reconnects, scope isolation, default-port URLs, padded/mismatched stored credentials, credential replacement, backup-restored orphan data, removal races, failed platform deletes and failed writes. - Follow-up regressions cover interrupted native Me-chat lookup, invite failure propagation, retry after an initial list failure, history deadlines, queued reconnects, escaped-path keys, unchanged credential re-adds and non-blocking startup cleanup. Reverting each of the eight behavior/caller/cleanup-order fixes fails its corresponding regression. - DM-name regression changes only the relay profile, verifies a full refresh updates the channel label and shared profile cache, and confirms ordinary reconnects avoid another profile request. The original cache-only implementation fails this regression. - Original signed-in iPhone 18 Pro debug simulator measurements: Buzz's 413 channels went from 6.26–6.30 s to approximately 1.5 s on returning; all three warmed communities switched in 1.47–1.54 s. Real socket pause restored the cached list offline and retained it on reconnect. These are debug simulator observations, not release-device benchmarks. - Integration with current main also passes the real-session resume/background/AUTH and live-admission/detach journeys. - Follow-up failure paths were exercised with deterministic provider/storage tests and widget journeys; the running simulator was not modified during this follow-up. Human acceptance remains pending; this PR stays draft. Try switching among previously visited communities, opening a channel, restarting and repeating. First visits and oversized snapshots require network loading. Cached metadata can be stale until refresh; it lives in ordinary preferences without additional application-level encryption. The snapshot contains no message bodies or credentials. Persistent disk-deletion failures can leave metadata until a later cleanup succeeds. --------- Signed-off-by: Star Lord <b89298dbe87c6b3fd8a425b535d9d161f23c88d555a47925ae0b04dfe02b201e@buzz.block.builderlab.xyz> Co-authored-by: Star Lord <b89298dbe87c6b3fd8a425b535d9d161f23c88d555a47925ae0b04dfe02b201e@buzz.block.builderlab.xyz> Co-authored-by: Rocket <0c41329ade659e01801116549bc617351689892a382bc864a1186dc9191293a7@buzz.block.builderlab.xyz> Co-authored-by: Groot <f4c08302591916fb4b80926bf7e18d22eef8aa0c877e4e841acc46405a45700b@buzz.block.builderlab.xyz> Co-authored-by: Mantis <530af7635ef7d0e1a5189d234338db88cb4ef1ede7119b4ebb4fb05c3eafe3b1@buzz.block.builderlab.xyz> |