Fix N+1 queries, add React.cache() session dedup, and parallelize async ops

Replace nested loop queries with batch fetches using inArray() across
discovery, tracking, metadata, settings, and system-health services.
The biggest win is getContinueWatchingFeed() going from ~375+ queries
to 5. Add a cached getSession() wrapper via React.cache() to deduplicate
auth lookups shared between layouts and pages. Parallelize independent
async operations in importTitle(), cacheImagesJob(), and the explore page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 12:07:54 -05:00
co-authored by Claude Opus 4.6
parent 107eb9a9e7
commit fb6c88e8f5
12 changed files with 361 additions and 245 deletions
+2 -3
View File
@@ -1,11 +1,10 @@
import { headers } from "next/headers";
import { Suspense } from "react";
import {
ContinueWatchingSectionSkeleton,
StatsSectionSkeleton,
TitleGridSectionSkeleton,
} from "@/components/skeletons";
import { auth } from "@/lib/auth/server";
import { getSession } from "@/lib/auth/session";
import { ContinueWatchingSection } from "./_components/continue-watching-section";
import { LibrarySection } from "./_components/library-section";
import { RecommendationsSection } from "./_components/recommendations-section";
@@ -13,7 +12,7 @@ import { StatsSection } from "./_components/stats-section";
import { WelcomeHeader } from "./_components/welcome-header";
export default async function DashboardPage() {
const session = await auth.api.getSession({ headers: await headers() });
const session = await getSession();
if (!session) return null;
return (