fix(perf): parallelize user data loading during NIP-07 login

Optimizes `handleAuthLogin` in `js/app.js` to run user data fetching (blocks, subscriptions, hashtag preferences) in the background instead of blocking the main UI render. This significantly improves perceived login speed, especially for users with large lists or slow NIP-07 extensions.

- Moves `userBlocks.seedWithNpubs` (which involves publishing) to background.
- Moves `subscriptions.ensureLoaded` and `hashtagPreferences.load` (which involve decryption) to background.
- Adds a race condition for `userBlocks.ensureLoaded` (read-only) with a short timeout to attempt early hydration without blocking indefinitely.
- Ensures the UI updates reactively when background data arrives via existing event listeners.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-28 18:02:37 +00:00
1 parent 4de479aaca
commit 90a74e7721
1 file changed
+49 -27
+49 -27
View File
@@ -4178,7 +4178,12 @@ class Application {
const hashtagPreferencesPromise = Promise.resolve(
this.loadHashtagPreferencesForPubkey(loginContext.pubkey),
);
).catch((error) => {
devLogger.warn(
"[Application] Background hashtag preferences load failed:",
error
);
});
if (this.zapController) {
try {
@@ -4266,7 +4271,7 @@ class Application {
}
await nwcPromise;
await hashtagPreferencesPromise;
// We do not await hashtagPreferencesPromise here; it loads in the background.
try {
await accessControl.ensureReady();
@@ -4279,37 +4284,54 @@ class Application {
if (activePubkey) {
const aggregatedBlacklist = accessControl.getBlacklist();
try {
await userBlocks.seedWithNpubs(
activePubkey,
Array.isArray(aggregatedBlacklist) ? aggregatedBlacklist : [],
);
} catch (error) {
if (
error?.code === "extension-permission-denied" ||
error?.code === "nip04-missing" ||
error?.name === "RelayPublishError"
) {
userLogger.error(
"[Application] Failed to seed shared block list after login:",
error,
);
} else {
devLogger.error(
"[Application] Unexpected error while seeding shared block list:",
error,
);
}
}
// Background the seeding process because it involves publishing events,
// which can block the login flow significantly.
userBlocks
.seedWithNpubs(
activePubkey,
Array.isArray(aggregatedBlacklist) ? aggregatedBlacklist : []
)
.catch((error) => {
if (
error?.code === "extension-permission-denied" ||
error?.code === "nip04-missing" ||
error?.name === "RelayPublishError"
) {
userLogger.error(
"[Application] Failed to seed shared block list after login:",
error
);
} else {
devLogger.error(
"[Application] Unexpected error while seeding shared block list:",
error
);
}
});
// Attempt to load blocks with a short timeout so we don't block the UI forever.
// If it times out, the UI will refresh reactively when the data arrives.
const blockLoadPromise = userBlocks.ensureLoaded(activePubkey);
const blockLoadTimeout = new Promise((resolve) =>
setTimeout(resolve, 2000)
);
try {
await subscriptions.ensureLoaded(activePubkey);
await Promise.race([blockLoadPromise, blockLoadTimeout]);
} catch (error) {
devLogger.warn(
"[Application] Failed to load subscriptions during login:",
error,
"[Application] Block list load timed out or failed:",
error
);
}
// Load subscriptions in the background to avoid blocking the main feed.
subscriptions.ensureLoaded(activePubkey).catch((error) => {
devLogger.warn(
"[Application] Failed to load subscriptions during login:",
error
);
});
}
try {