Skip to content

Commit 20012b1

Browse files
committed
fix: improve admin panel performance
1 parent 8f38f58 commit 20012b1

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

lark-ui/src/routes/admin/+page.server.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,31 @@ export const load: PageServerLoad = async ({ fetch }) => {
2222
throw redirect(302, '/app/projects');
2323
}
2424

25-
const [submissionsResponse, projectsResponse, usersResponse, metricsResponse, shopItemsResponse, shopTransactionsResponse] = await Promise.all([
26-
fetch(`${apiUrl}/api/admin/submissions`, { credentials: 'include' }),
27-
fetch(`${apiUrl}/api/admin/projects`, { credentials: 'include' }),
28-
fetch(`${apiUrl}/api/admin/users`, { credentials: 'include' }),
29-
fetch(`${apiUrl}/api/admin/metrics`, { credentials: 'include' }),
30-
fetch(`${apiUrl}/api/shop/admin/items`, { credentials: 'include' }),
31-
fetch(`${apiUrl}/api/shop/admin/transactions`, { credentials: 'include' }),
32-
]);
33-
34-
if (!submissionsResponse.ok || !projectsResponse.ok || !usersResponse.ok || !metricsResponse.ok) {
35-
throw error(500, 'Failed to load admin resources');
36-
}
25+
let metrics = {
26+
totalHackatimeHours: 0,
27+
totalApprovedHours: 0,
28+
totalUsers: 0,
29+
totalProjects: 0,
30+
totalSubmittedHackatimeHours: 0,
31+
};
3732

38-
const submissions = await submissionsResponse.json();
39-
const projects = await projectsResponse.json();
40-
const users = await usersResponse.json();
41-
const metrics = await metricsResponse.json();
42-
const shopItems = shopItemsResponse.ok ? await shopItemsResponse.json() : [];
43-
const shopTransactions = shopTransactionsResponse.ok ? await shopTransactionsResponse.json() : [];
33+
try {
34+
const metricsResponse = await fetch(`${apiUrl}/api/admin/metrics`, { credentials: 'include' });
35+
if (metricsResponse.ok) {
36+
const metricsData = await metricsResponse.json();
37+
metrics = metricsData.totals ?? metricsData;
38+
}
39+
} catch {
40+
}
4441

4542
return {
4643
user,
47-
submissions,
48-
projects,
49-
users,
50-
metrics: metrics.totals ?? metrics,
51-
shopItems,
52-
shopTransactions,
44+
submissions: [],
45+
projects: [],
46+
users: [],
47+
metrics,
48+
shopItems: [],
49+
shopTransactions: [],
5350
apiUrl,
5451
};
5552
};

lark-ui/src/routes/admin/+page.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ let metrics = $state<AdminMetrics>(
190190
let shopItems = $state<ShopItem[]>(data.shopItems ?? []);
191191
let shopTransactions = $state<ShopTransaction[]>(data.shopTransactions ?? []);
192192
193-
let submissionsLoaded = $state((data.submissions?.length ?? 0) > 0);
194-
let projectsLoaded = $state((data.projects?.length ?? 0) > 0);
195-
let usersLoaded = $state((data.users?.length ?? 0) > 0);
196-
let shopLoaded = $state((data.shopItems?.length ?? 0) > 0 || (data.shopTransactions?.length ?? 0) > 0);
193+
let submissionsLoaded = $state(false);
194+
let projectsLoaded = $state(false);
195+
let usersLoaded = $state(false);
196+
let shopLoaded = $state(false);
197+
let initialLoadDone = $state(false);
197198
198199
let searchQuery = $state('');
199200
let selectedStatuses = $state<Set<string>>(new Set());
@@ -1043,6 +1044,13 @@ async function recalculateAllProjectsHours() {
10431044
}
10441045
}
10451046
1047+
$effect(() => {
1048+
if (!initialLoadDone && typeof window !== 'undefined') {
1049+
initialLoadDone = true;
1050+
loadSubmissions(true);
1051+
}
1052+
});
1053+
10461054
$effect(() => {
10471055
if (submissions.length === 0) {
10481056
return;

owl-api/src/auth/auth.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export class AuthService {
140140
otpCode: otp,
141141
otpExpiresAt: { gt: new Date() },
142142
isVerified: false,
143+
user: {
144+
email: email,
145+
},
143146
},
144147
include: { user: true },
145148
});

0 commit comments

Comments
 (0)