diff options
| author | Adam Soltys <[email protected]> | 2026-10-07 07:24:33 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-07 07:24:33 -0700 |
| commit | 78cf670939133fc4f656f0f42b21a59431a53842 (patch) | |
| tree | 745ec53290fe37c91fb607e6013a322b887f9388 /src/recipient-search.js | |
| parent | 5bb7da55232c7a1debed2a505a85b5e7da5ba6db (diff) | |
| download | coinosv3-78cf670939133fc4f656f0f42b21a59431a53842.tar.gz coinosv3-78cf670939133fc4f656f0f42b21a59431a53842.zip | |
Rebuildable caches move from localStorage to IndexedDB (cache-store.js)
localStorage is ~5M characters per site whatever the device, and a phone
had filled it. Profiles, faceless list, reports, follow packs, profile
pages, relay lists, the moderation baseline, community directory, link
previews, video sizes/probes and search profiles (~3M on that phone) now
live in IndexedDB, which shares the site's disk allowance (GBs).
cacheStorage keeps localStorage's string API: reads from memory,
coalesced write-behind, flushed on hide. Copies migrate on open and are
removed once written. Boot waits for it (max 3s) beside the Ark store;
caches read at construction re-merge on ready; an early write can't
replace the stored copy. A copy an older build writes to localStorage
later moves in on first ask. Wallet wipes reach it; private mode stays on
localStorage. Read markers, drafts, follows, note threads and sync
outboxes stay in localStorage on purpose (cross-tab consistency, early
server-rendered seeding). Also asks navigator.storage.persist().
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/recipient-search.js')
| -rw-r--r-- | src/recipient-search.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/recipient-search.js b/src/recipient-search.js index fdeaeaf..5909078 100644 --- a/src/recipient-search.js +++ b/src/recipient-search.js @@ -10,6 +10,7 @@ import { queryOn, parseNostrPubkey, npubOf, PROFILE_RELAYS } from './nostr.js'; import { assetUrl } from './asset-url.js'; +import { cacheStorage, onCacheReady } from './cache-store.js'; // coinos punks: the deterministic default avatar — same formula the coinos // app uses (last byte of the pubkey picks one of 64). Initials show through @@ -118,8 +119,17 @@ const QUERY_TTL = 12 * 3600_000; const profileCache = new Map(); // pk -> { name, picture } const queryCache = new Map(); // q -> rows const queryAt = new Map(); // q -> when the rows were fetched +// the profile half lives in IndexedDB (cache-store.js): read again once it +// opens, keeping whatever this session already learned +const loadSearchProfiles = () => { + try { + for (const [pk, v] of Object.entries(JSON.parse(cacheStorage.getItem(PROF_KEY) || '{}'))) + if (!profileCache.has(pk)) profileCache.set(pk, v); + } catch {} +}; +loadSearchProfiles(); +onCacheReady(loadSearchProfiles); try { - for (const [pk, v] of Object.entries(JSON.parse(localStorage.getItem(PROF_KEY) || '{}'))) profileCache.set(pk, v); const now = Date.now(); for (const [q, e] of Object.entries(JSON.parse(localStorage.getItem(QUERY_KEY) || '{}'))) if (e && Array.isArray(e.rows) && now - (e.t || 0) < QUERY_TTL) { queryCache.set(q, e.rows); queryAt.set(q, e.t); } @@ -131,7 +141,7 @@ function persistCaches() { try { const prof = {}; for (const [pk, v] of [...profileCache].slice(-200)) prof[pk] = { name: v.name || null, picture: v.picture || null }; - localStorage.setItem(PROF_KEY, JSON.stringify(prof)); + cacheStorage.setItem(PROF_KEY, JSON.stringify(prof)); const qs = {}; for (const [q, rows] of [...queryCache].slice(-60)) qs[q] = { t: queryAt.get(q) || Date.now(), rows }; localStorage.setItem(QUERY_KEY, JSON.stringify(qs)); |
