mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 21:02:28 +00:00
Fix slow Nostr list sync by decoupling from profile and awaiting before feed render
The login-to-feed pipeline had several issues causing lists (blocks, subscriptions, hashtag preferences) to load too slowly or not reflect in the feed: 1. All list loading was chained after profileStatePromise, adding 2.5-6s of unnecessary delay. Lists only need relay URLs, not profile data. Now they chain off relaysReadyPromise instead, loading in parallel with profile fetching. 2. The video grid refreshed immediately without waiting for any lists, so the feed briefly displayed unfiltered content. Now the grid refresh waits (up to 8s) for critical feed-filtering lists to settle. 3. Hashtag preferences weren't cached into the snapshot before the feed rendered, so interests/disinterests were empty on first paint. 4. Subscription ensureLoaded had a 6s timeout that was too aggressive for relay fetch (12s) + decryption (3-12s), causing silent failures. Increased to 30s. 5. Subscription relay fetches for user and session actor ran sequentially. Now they run in parallel via Promise.all. https://claude.ai/code/session_01UKmTWb83AnQPRVQo3bKZqm
This commit is contained in:
3 files changed
+88
-38
No files matched your search
+32
-20
@@ -502,14 +502,19 @@ class SubscriptionsManager {
|
||||
);
|
||||
const hadCachedSnapshot = cachedSnapshot.hasSnapshot;
|
||||
const shouldForceFullFetch = !cachedSnapshot.hasSnapshot;
|
||||
let events = await nostrClient.fetchListIncrementally({
|
||||
kind: SUBSCRIPTION_SET_KIND,
|
||||
pubkey: normalizedUserPubkey,
|
||||
dTag: SUBSCRIPTION_LIST_IDENTIFIER,
|
||||
relayUrls,
|
||||
since: shouldForceFullFetch ? 0 : (cachedSnapshot.createdAt || 0),
|
||||
timeoutMs: 12000,
|
||||
});
|
||||
|
||||
// Fetch user and session actor subscription lists in parallel to reduce
|
||||
// total relay wait time during login.
|
||||
const fetchPromises = [
|
||||
nostrClient.fetchListIncrementally({
|
||||
kind: SUBSCRIPTION_SET_KIND,
|
||||
pubkey: normalizedUserPubkey,
|
||||
dTag: SUBSCRIPTION_LIST_IDENTIFIER,
|
||||
relayUrls,
|
||||
since: shouldForceFullFetch ? 0 : (cachedSnapshot.createdAt || 0),
|
||||
timeoutMs: 12000,
|
||||
}),
|
||||
];
|
||||
|
||||
const normalizedSessionActorPubkey = normalizeNostrPubkey(
|
||||
nostrClient?.sessionActor?.pubkey,
|
||||
@@ -525,17 +530,22 @@ class SubscriptionsManager {
|
||||
),
|
||||
);
|
||||
const shouldForceSessionFetch = !sessionCachedSnapshot.hasSnapshot;
|
||||
const sessionEvents = await nostrClient.fetchListIncrementally({
|
||||
kind: SUBSCRIPTION_SET_KIND,
|
||||
pubkey: normalizedSessionActorPubkey,
|
||||
dTag: SUBSCRIPTION_LIST_IDENTIFIER,
|
||||
relayUrls,
|
||||
since: shouldForceSessionFetch ? 0 : (sessionCachedSnapshot.createdAt || 0),
|
||||
timeoutMs: 12000,
|
||||
});
|
||||
if (sessionEvents.length) {
|
||||
events = events.concat(sessionEvents);
|
||||
}
|
||||
fetchPromises.push(
|
||||
nostrClient.fetchListIncrementally({
|
||||
kind: SUBSCRIPTION_SET_KIND,
|
||||
pubkey: normalizedSessionActorPubkey,
|
||||
dTag: SUBSCRIPTION_LIST_IDENTIFIER,
|
||||
relayUrls,
|
||||
since: shouldForceSessionFetch ? 0 : (sessionCachedSnapshot.createdAt || 0),
|
||||
timeoutMs: 12000,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const fetchResults = await Promise.all(fetchPromises);
|
||||
let events = fetchResults[0] || [];
|
||||
if (shouldFetchSessionActor && fetchResults[1]?.length) {
|
||||
events = events.concat(fetchResults[1]);
|
||||
}
|
||||
|
||||
const mergedEvents = [];
|
||||
@@ -809,7 +819,9 @@ class SubscriptionsManager {
|
||||
|
||||
try {
|
||||
// Race against a timeout so the UI doesn't hang indefinitely if relays stall.
|
||||
const timeoutMs = 6000;
|
||||
// The timeout must accommodate relay fetch (~12s) + decryption (~3-12s per
|
||||
// scheme attempt), so we use 30s to give the full pipeline enough room.
|
||||
const timeoutMs = 30000;
|
||||
await Promise.race([
|
||||
loader,
|
||||
new Promise((_, reject) =>
|
||||
|
||||
Reference in new issue
Block a user