mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-28 08:22:24 +00:00
Optimize application startup speed by parallelizing initialization
This commit is contained in:
1 parent
e1d43708c5
commit
29857dc36c
2 files changed
+24
-15
No files matched your search
+11
-13
@@ -433,22 +433,20 @@ class AccessControl {
|
||||
}
|
||||
|
||||
async ensureReady() {
|
||||
// If not loaded and not already refreshing, kick off a background refresh.
|
||||
// We do NOT await this promise, allowing the application to proceed immediately.
|
||||
// Reactive updates (e.g. onBlacklistChange) will handle the UI state when data arrives.
|
||||
if (!this.hasLoaded && !this._isRefreshing) {
|
||||
this.refresh();
|
||||
this.refresh().catch((error) => {
|
||||
userLogger.warn(
|
||||
"[accessControl] Background refresh failed:",
|
||||
error,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await this._refreshPromise;
|
||||
userLogger.info("[accessControl] ensureReady resolved");
|
||||
} catch (error) {
|
||||
if (!this.hasLoaded) {
|
||||
userLogger.warn("[accessControl] ensureReady retry");
|
||||
await this.refresh();
|
||||
await this._refreshPromise;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// Always resolve immediately to prevent blocking application startup.
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
whitelistMode() {
|
||||
|
||||
@@ -436,9 +436,20 @@ class Application {
|
||||
profileModalPromise,
|
||||
]);
|
||||
|
||||
const nostrInitPromise = nostrClient.init();
|
||||
// Initialize the pool early to unblock bootstrapTrustedSeeds,
|
||||
// but do NOT await the full connection process here.
|
||||
try {
|
||||
await nostrClient.ensurePool();
|
||||
} catch (poolError) {
|
||||
devLogger.warn("[app.init()] Pool ensure failed:", poolError);
|
||||
}
|
||||
|
||||
await Promise.all([modalBootstrapPromise, nostrInitPromise]);
|
||||
// Kick off relay connection in the background.
|
||||
const nostrInitPromise = nostrClient.init().catch((err) => {
|
||||
devLogger.warn("[app.init()] Background nostrClient.init failed:", err);
|
||||
});
|
||||
|
||||
await modalBootstrapPromise;
|
||||
|
||||
try {
|
||||
await bootstrapTrustedSeeds();
|
||||
|
||||
Reference in new issue
Block a user