mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix(auth): defer watch-history preload so it doesn't starve the critical lists
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 <[email protected]>
This commit is contained in:
1 parent
39aa81fb23
commit
5a45ec7bf5
1 file changed
+18
-18
@@ -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),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user