refactor(account): simplify org aggregation
parent
fa92f0590c
commit
3506081f40
|
|
@ -301,17 +301,15 @@ export namespace Account {
|
||||||
|
|
||||||
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
|
const orgsByAccount = Effect.fn("Account.orgsByAccount")(function* () {
|
||||||
const accounts = yield* repo.list()
|
const accounts = yield* repo.list()
|
||||||
const [errors, results] = yield* Effect.partition(
|
return yield* Effect.forEach(
|
||||||
accounts,
|
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 },
|
{ 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) {
|
const orgs = Effect.fn("Account.orgs")(function* (accountID: AccountID) {
|
||||||
|
|
|
||||||
|
|
@ -75,17 +75,7 @@ export const ExperimentalRoutes = lazy(() =>
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const [accounts, active] = await Promise.all([Account.list(), Account.active()])
|
const [groups, active] = await Promise.all([Account.orgsByAccount(), 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 orgs = groups.flatMap((group) =>
|
const orgs = groups.flatMap((group) =>
|
||||||
group.orgs.map((org) => ({
|
group.orgs.map((org) => ({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue