perf(web): shorten the first open of a space for new members

Accepting an invitation no longer waits for the vault sync, the redundant
join right after joining is skipped, and the crypto state, first log page and
channel metadata are requested in parallel.
This commit is contained in:
justme committed 2026-10-16 05:34:38 +08:00
1 parent d4a72bf177
commit 06fe077ef1
6 files changed
+26 -9

No files matched your search

@@ -27,7 +27,15 @@ export function attachDataKeys(session: ChannelSession, resource: SavedResource)
objectKeys.set(`${resource.id}:${itemId}`, unwrapped); return unwrapped;
};
}
export async function readDataKeys(resource: SavedResource, session: ChannelSession): Promise<{ state: CryptoState; keys: Record<string, string> }> {
type DataKeys = { state: CryptoState; keys: Record<string, string> };
const pendingKeys = new Map<string, Promise<DataKeys>>();
/** 同一空间同时发起的读取合并成一次请求 */
export function readDataKeys(resource: SavedResource, session: ChannelSession): Promise<DataKeys> {
let task = pendingKeys.get(resource.id);
if (!task) { task = loadDataKeys(resource, session).finally(() => pendingKeys.delete(resource.id)); pendingKeys.set(resource.id, task); }
return task;
}
async function loadDataKeys(resource: SavedResource, session: ChannelSession): Promise<DataKeys> {
const state = await apiFetch(`/spaces/${resource.id}/crypto`, { headers: session.authHeaders(session.can('owner') ? 'owner' : 'read') }).then(r => r.json() as Promise<CryptoState>);
states.set(resource.id, state);
const latest = await getResource(resource.id); const keys = { ...latest?.domainKeys };