perf(web): shorten the cold start when opening a saved space
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was successful

Activate the account with parallel requests, run the full vault sync in the
background, skip the duplicate space list request, and send the rejoin
together with the first screen of data. [CI]
This commit is contained in:
justme committed 2026-10-16 06:00:17 +08:00
1 parent f2e118c966
commit b1ac11e1d7
3 files changed
+19 -11

No files matched your search

+11 -7
View File
@@ -106,14 +106,17 @@ async function syncVault(): Promise<void> {
async function activate(identity: { username: string; token: string }, key: CryptoKey, remote: VaultBody, remember = true, cachedPersonal?: PersonalProfile): Promise<AccountSession> {
const profile = validateVault(await openJson(remote.vault, key));
const deviceSigning = await ensureDeviceSigning(identity.username, identity.token, profile.keys.signing);
// 设备签名密钥与个人资料互不依赖,同时请求,冷启动少等一个往返
const [deviceSigning, personal] = await Promise.all([
ensureDeviceSigning(identity.username, identity.token, profile.keys.signing),
loadPersonal(identity.token).catch((error: unknown) => {
if (!(error instanceof Error && error.message === '网络连接失败')) throw error;
return cachedPersonal;
}),
]);
clearResourceSessions(); setResourceScope(identity.username);
const session: AccountSession = { ...identity, key, profile, revision: remote.revision, remember, controller: new AbortController(), dirty: false, deviceSigning };
try { session.personal = await loadPersonal(identity.token); }
catch (error) {
if (!(error instanceof Error && error.message === '网络连接失败')) throw error;
session.personal = cachedPersonal;
}
session.personal = personal;
account = session; setAccountIdentity(identity, profile.keys.publicKey, session.personal);
await applyProfile(mergeVault(profile, await listAllResources(), await listResourceDeletes()));
setResourceChangeListener(scheduleSync);
@@ -135,7 +138,8 @@ export function restoreAccount(): Promise<void> {
try {
const session = await activate(saved, saved.key, remote, true, saved.personal);
setAccountIdentity(session, session.profile.keys.publicKey, session.personal);
await syncVault().catch(() => {});
// 保险库已在 activate 里并入本机资源,完整同步(约 4 次往返)放到后台,不挡住打开页面
void syncVault().catch(() => {});
} catch (error) { await logoutAccount(); throw error; }
})().catch((error: unknown) => { restoration = undefined; throw error; });
return restoration;