refactor(account): simplify org aggregation

kit/console-org-switcher
Kit Langton 2026-04-04 11:13:37 -04:00
parent fa92f0590c
commit 3506081f40
2 changed files with 7 additions and 19 deletions

View File

@ -301,17 +301,15 @@ export namespace Account {
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
const accounts = yield* repo.list()
const [errors, results] = yield* Effect.partition(
return yield* Effect.forEach(
accounts,
(account) => orgs(account.id).pipe(Effect.map((orgs) => ({ account, orgs }))),
(account) =>
orgs(account.id).pipe(
Effect.catch(() => Effect.succeed([] as readonly Org[])),
Effect.map((orgs) => ({ account, orgs })),
),
{ concurrency: 3 },
)
for (const error of errors) {
yield* Effect.logWarning("failed to fetch orgs for account").pipe(
Effect.annotateLogs({ error: String(error) }),
)
}
return results
})
const orgs = Effect.fn("Account.orgs")(function* (accountID: AccountID) {

View File

@ -75,17 +75,7 @@ export const ExperimentalRoutes = lazy(() =>
},
}),
async (c) => {
const [accounts, active] = await Promise.all([Account.list(), Account.active()])
const groups = await Promise.all(
accounts.map(async (account) => {
try {
const orgs = await Account.orgs(account.id)
return { account, orgs }
} catch {
return { account, orgs: [] }
}
}),
)
const [groups, active] = await Promise.all([Account.orgsByAccount(), Account.active()])
const orgs = groups.flatMap((group) =>
group.orgs.map((org) => ({