foundry: parallelize app snapshot org reads

This commit is contained in:
Nathan Flurry 2026-03-13 01:04:50 -07:00
parent 6e216a9f86
commit 252fbdc93b
2 changed files with 18 additions and 13 deletions

View file

@ -29,6 +29,7 @@ WorkspaceActor
- Branch rename is a real git operation, not just metadata. - Branch rename is a real git operation, not just metadata.
- `SandboxInstanceActor` stays separate from `TaskActor`; tasks/sessions reference it by identity. - `SandboxInstanceActor` stays separate from `TaskActor`; tasks/sessions reference it by identity.
- Sync actors are polling workers only. They feed parent actors and should not become the source of truth. - Sync actors are polling workers only. They feed parent actors and should not become the source of truth.
- When a backend request path must aggregate multiple independent actor calls or reads, prefer bounded parallelism over sequential fan-out when correctness permits. Do not serialize independent work by default.
## Maintenance ## Maintenance

View file

@ -230,19 +230,23 @@ async function buildAppSnapshot(c: any, sessionId: string): Promise<FoundryAppSn
const session = await requireAppSessionRow(c, sessionId); const session = await requireAppSessionRow(c, sessionId);
const eligibleOrganizationIds = parseEligibleOrganizationIds(session.eligibleOrganizationIdsJson); const eligibleOrganizationIds = parseEligibleOrganizationIds(session.eligibleOrganizationIdsJson);
const organizations: FoundryOrganization[] = []; const organizations = (
for (const organizationId of eligibleOrganizationIds) { await Promise.all(
eligibleOrganizationIds.map(async (organizationId) => {
try { try {
const workspace = await getOrCreateWorkspace(c, organizationId); const workspace = await getOrCreateWorkspace(c, organizationId);
const organizationState = await getOrganizationState(workspace); const organizationState = await getOrganizationState(workspace);
organizations.push(organizationState.snapshot); return organizationState.snapshot;
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : String(error); const message = error instanceof Error ? error.message : String(error);
if (!message.includes("Actor not found")) { if (!message.includes("Actor not found")) {
throw error; throw error;
} }
return null;
} }
} }),
)
).filter((organization): organization is FoundryOrganization => organization !== null);
const currentUser: FoundryUser | null = session.currentUserId const currentUser: FoundryUser | null = session.currentUserId
? { ? {