mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Consolidates the persisted-plaintext-decrypt-cache pattern (already used by watch history) into a shared factory, persistedPlaintextCache.js, and adds a DM cache on top of it. watchHistoryDecryptCache now delegates to the factory (same public API; tests unchanged). decryptDirectMessageEvent now also consults/writes a persisted cache keyed by the immutable DM event id (JSON of the decrypt result; flushed once per listDirectMessages batch; cleared on logout alongside the in-memory cache). DM events never change, so a reload re-decrypts only messages it has not seen and skips the (serialized, slow) nip-07 extension for the rest. Harness (dm-repro, now cold/warm): 20 DMs -> COLD nip04.decrypt 50, WARM 0 — reloads cost zero extension decrypt calls. Also excludes the actor's own key from NIP-04 remote candidates (decrypting against self is always wasted). DM unit + integration and watch-history cache tests green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
15 lines
744 B
JavaScript
15 lines
744 B
JavaScript
// Persisted cache of decrypted watch-history chunk plaintext, keyed by the
|
|
// immutable chunk event id. Backed by the shared persisted-plaintext-cache
|
|
// factory (see persistedPlaintextCache.js). An unchanged chunk keeps its event
|
|
// id, so reloads decrypt only the chunk(s) that actually changed and skip the
|
|
// nip-07 extension for the rest. Cleared on logout.
|
|
|
|
import { createPersistedPlaintextCache } from "./persistedPlaintextCache.js";
|
|
|
|
const cache = createPersistedPlaintextCache("bitvid:whDecryptedChunks:v1", 400);
|
|
|
|
export const getCachedChunkPlaintext = cache.get;
|
|
export const setCachedChunkPlaintext = cache.set;
|
|
export const flushDecryptedChunkCache = cache.flush;
|
|
export const clearWatchHistoryDecryptedChunkCache = cache.clear;
|