Browse Source

perf(dashboard): expand SSR prefetch to include overview data

ding113 1 week ago
parent
commit
d2abe5ea3e

+ 3 - 0
src/app/[locale]/dashboard/_components/bento/dashboard-bento.tsx

@@ -37,6 +37,7 @@ interface DashboardBentoProps {
   currencyCode: CurrencyCode;
   allowGlobalUsageView: boolean;
   initialStatistics?: UserStatisticsData;
+  initialOverview?: OverviewData;
 }
 
 interface LeaderboardData {
@@ -114,6 +115,7 @@ export function DashboardBento({
   currencyCode,
   allowGlobalUsageView,
   initialStatistics,
+  initialOverview,
 }: DashboardBentoProps) {
   const t = useTranslations("customs");
   const tl = useTranslations("dashboard.leaderboard");
@@ -126,6 +128,7 @@ export function DashboardBento({
     queryFn: fetchOverviewData,
     refetchInterval: 15_000,
     staleTime: 10_000,
+    initialData: initialOverview,
   });
 
   // Active sessions

+ 4 - 1
src/app/[locale]/dashboard/_components/dashboard-bento-sections.tsx

@@ -1,4 +1,5 @@
 import { cache } from "react";
+import { getOverviewData } from "@/actions/overview";
 import { getUserStatistics } from "@/actions/statistics";
 import { getSystemSettings } from "@/repository/system-config";
 import { DEFAULT_TIME_RANGE } from "@/types/statistics";
@@ -11,9 +12,10 @@ interface DashboardBentoSectionProps {
 }
 
 export async function DashboardBentoSection({ isAdmin }: DashboardBentoSectionProps) {
-  const [systemSettings, statistics] = await Promise.all([
+  const [systemSettings, statistics, overviewResult] = await Promise.all([
     getCachedSystemSettings(),
     getUserStatistics(DEFAULT_TIME_RANGE),
+    getOverviewData(),
   ]);
 
   return (
@@ -22,6 +24,7 @@ export async function DashboardBentoSection({ isAdmin }: DashboardBentoSectionPr
       currencyCode={systemSettings.currencyDisplay}
       allowGlobalUsageView={systemSettings.allowGlobalUsageView}
       initialStatistics={statistics.ok ? statistics.data : undefined}
+      initialOverview={overviewResult.ok ? overviewResult.data : undefined}
     />
   );
 }