wait calls wrapped in Promise.all
This commit is contained in:
@@ -238,7 +238,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Nav -->
|
||||
<nav class="mt-0 flex flex-1 flex-col gap-0.5 px-3" data-sveltekit-preload-data="hover">
|
||||
<nav class="mt-0 flex flex-1 flex-col gap-0.5 px-3">
|
||||
{#each [
|
||||
{ href: '/', label: 'Dashboard', icon: 'dashboard' },
|
||||
{ href: '/matches', label: 'Matches', icon: 'matches' },
|
||||
|
||||
@@ -17,26 +17,23 @@ export const load: PageServerLoad = async ({ locals }) => {
|
||||
}
|
||||
|
||||
// ── LOGGED IN → dashboard data ──
|
||||
const recentMatches = await db.query.match.findMany({
|
||||
with: { participants: { with: { team: true } }, mappool: { with: { slots: true } } },
|
||||
orderBy: desc(match.createdAt),
|
||||
limit: 5
|
||||
});
|
||||
|
||||
const liveMatches = await db.query.match.findMany({
|
||||
with: { participants: { with: { team: true } }, mappool: { with: { slots: true } } },
|
||||
where: inArray(match.state, ['LOBBY', 'ROLLING', 'PICKING', 'PLAYING'])
|
||||
});
|
||||
|
||||
const [matchCount] = await db.select({ count: count() }).from(match);
|
||||
const [teamCount] = await db.select({ count: count() }).from(team);
|
||||
const [poolCount] = await db.select({ count: count() }).from(mappool);
|
||||
const [finishedCount] = await db
|
||||
.select({ count: count() })
|
||||
.from(match)
|
||||
.where(eq(match.state, 'FINISHED'));
|
||||
|
||||
const queueStatus = await getQueueStatus(locals.user.id);
|
||||
const [recentMatches, liveMatches, [matchCount], [teamCount], [poolCount], [finishedCount], queueStatus] =
|
||||
await Promise.all([
|
||||
db.query.match.findMany({
|
||||
with: { participants: { with: { team: true } }, mappool: { with: { slots: true } } },
|
||||
orderBy: desc(match.createdAt),
|
||||
limit: 5
|
||||
}),
|
||||
db.query.match.findMany({
|
||||
with: { participants: { with: { team: true } }, mappool: { with: { slots: true } } },
|
||||
where: inArray(match.state, ['LOBBY', 'ROLLING', 'PICKING', 'PLAYING'])
|
||||
}),
|
||||
db.select({ count: count() }).from(match),
|
||||
db.select({ count: count() }).from(team),
|
||||
db.select({ count: count() }).from(mappool),
|
||||
db.select({ count: count() }).from(match).where(eq(match.state, 'FINISHED')),
|
||||
getQueueStatus(locals.user.id)
|
||||
]);
|
||||
|
||||
return {
|
||||
authenticated: true as const,
|
||||
|
||||
Reference in New Issue
Block a user