From 0c8a17e3cf07cbc41beaf72ad4ef95a2d6b17ff3 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 12 Jun 2026 14:18:09 -0400 Subject: [PATCH] perf(watch-history): eagerly preload on login (was lazy until For You/history tab) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Watch history was never loaded as part of the login cascade — it only loaded when the For You feed refreshed or the history tab was opened. So on login (and on other feeds) watched-video suppression and watch-history tags did nothing until the user navigated there. Kick off a non-blocking watchHistoryService.loadLatest() during the login list-sync (deliberately NOT in parallelListTasks, so the feed never waits for it). loadLatest schedules the background refresh, which emits "fingerprint" and the For You feed re-runs (feedCoordinator) to apply suppression once resolved. Deduped against the feed's own loadLatest via the in-flight refresh promise. Co-Authored-By: Claude Opus 4.8 --- js/app/authSessionCoordinator.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/app/authSessionCoordinator.js b/js/app/authSessionCoordinator.js index 8cef0472..d0007d26 100644 --- a/js/app/authSessionCoordinator.js +++ b/js/app/authSessionCoordinator.js @@ -11,6 +11,7 @@ import { clearDecryptionSchemeCache } from "../nostr/decryptionSchemeCache.js"; import { clearWatchHistoryConversationKeyCache } from "../nostr/watchHistory.js"; +import watchHistoryService from "../watchHistoryService.js"; import { FEED_TYPES } from "../constants.js"; /** @@ -419,6 +420,26 @@ export function createAuthSessionCoordinator(deps) { const parallelListTasks = []; + // Eagerly warm watch history in the background on login (NOT awaited / + // not in parallelListTasks — the feed must never wait for it). loadLatest + // schedules the background refresh, which emits "fingerprint" so the For + // You feed re-runs (see feedCoordinator) to suppress watched videos. + // Without this it only loaded when For You or the history tab was opened. + if ( + activePubkey && + watchHistoryService && + typeof watchHistoryService.loadLatest === "function" + ) { + Promise.resolve( + watchHistoryService.loadLatest(activePubkey, { allowStale: true }), + ).catch((error) => { + devLogger.warn( + "[auth] Background watch-history preload failed:", + error, + ); + }); + } + if ( activePubkey && typeof this.authService.loadBlocksForPubkey === "function"