Files
sofa/lib/auth/session.ts
T
jakeandClaude Opus 4.6 fb6c88e8f5 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>
2026-03-05 12:07:54 -05:00

14 lines
461 B
TypeScript

import { headers } from "next/headers";
import { cache } from "react";
import { auth } from "./server";
/**
* Cached session getter — deduplicated per request via React.cache().
* Use this instead of calling auth.api.getSession() directly in server
* components and layouts to avoid redundant session lookups within a
* single render pass.
*/
export const getSession = cache(async () => {
return auth.api.getSession({ headers: await headers() });
});