From 5a45ec7bf56918f0df6ce7d0e4d43868dfa70fe8 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 12 Jun 2026 20:06:57 -0400 Subject: [PATCH] fix(auth): defer watch-history preload so it doesn't starve the critical lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression from the eager watch-history preload (0c8a17e3): it fired BEFORE the blocks/subscriptions/hashtags list sync. The nip-07 extension serializes all decrypt calls, and a cold watch history is ~150+ chunk decrypts — so those queued ahead of the small critical lists, which then timed out ("hashtags not working / subscriptions super slow") while watch history slowly drained the extension (~20s). Move the preload to AFTER Promise.all(parallelListTasks) so the small, critical lists decrypt first, then watch history warms in the background. Still non-blocking; still emits "fingerprint" for the For You re-run. Co-Authored-By: Claude Opus 4.8 --- js/app/authSessionCoordinator.js | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/js/app/authSessionCoordinator.js b/js/app/authSessionCoordinator.js index 0df14c03..1d9d9103 100644 --- a/js/app/authSessionCoordinator.js +++ b/js/app/authSessionCoordinator.js @@ -421,24 +421,6 @@ export function createAuthSessionCoordinator(deps) { const parallelListTasks = []; - // Eagerly warm watch history in the background on login (NOT awaited). - // loadLatest schedules the refresh, which emits "fingerprint" so the For - // You feed re-runs (feedCoordinator) to suppress watched videos. - 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" @@ -510,6 +492,24 @@ export function createAuthSessionCoordinator(deps) { } const taskOutcomes = await Promise.all(parallelListTasks); + + // Warm watch history AFTER the critical lists decrypt: the serialized + // nip-07 extension + a cold watch history (~150+ decrypts) starved them. + 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, + ); + }); + } + const requiredTaskOutcomes = taskOutcomes.filter((outcome) => ["blocks", "subscriptions", "hashtags"].includes(outcome.name), );