Merge pull request #1889 from PR0M3TH3AN/fix/optimize-nip07-login-perf-4235940878368250470

fix(perf): optimize NIP-07 login and user data loading speed
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-28 13:11:14 -05:00
commit fa3610f4f7
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 {