perf(cache): edge-cache tmdb proxy, call tmdb directly on server, enable ISR
Three exceeded Vercel free tier limits (edge requests, function invocations, fast origin transfer) all traced back to nothing being cached. - Http defaults preventCache to false and the tmdb proxy now sends a real Cache-Control, so public responses are edge cached instead of missing on every request. Session scoped calls keep private, no-store. - On the server movieAdvisor talks to tmdb directly. It used to fetch its own public /api/tmdb url, billing a second edge request, a second function invocation and the whole payload as origin transfer per server render. - Add generateStaticParams to movie, tv and person pages. Without it Next treats the segment as fully dynamic and ignores revalidate, so the pages re-rendered on every request instead of using ISR. - Trim credits and person payloads in the proxy: credits 72kb to 13kb, aggregate_credits 308kb to 102kb, person 191kb to 124kb. Only fields no mapper reads are dropped, mapped output is unchanged. - Detail pages are cached now, so only a real tmdb 404 becomes notFound and other failures bubble up instead of being baked in as a 404 for a day. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ecc57ff135
commit
01792a9669
10 files changed
+145
-34
No files matched your search
@@ -2,6 +2,8 @@ import { createShowMetadata, createShowPage } from '../../showPage';
|
||||
|
||||
export const revalidate = 86400;
|
||||
|
||||
export const generateStaticParams = async () => [];
|
||||
|
||||
export const generateMetadata = createShowMetadata('movie');
|
||||
|
||||
const MoviePage = createShowPage('movie');
|
||||
|
||||
@@ -6,7 +6,7 @@ import JsonLd from '@/components/JsonLd';
|
||||
import detailsQuery from '@/data/queries/details';
|
||||
import { SITE_URL, TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
import { showPath } from '@/lib/utils';
|
||||
import { isMissing, showPath } from '@/lib/utils';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -41,8 +41,10 @@ export const createShowMetadata =
|
||||
url: path
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
return notFound();
|
||||
} catch (error) {
|
||||
if (isMissing(error)) return notFound();
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,7 +56,11 @@ export const createShowPage = (showType: Show['type']) => {
|
||||
|
||||
if (!showId) return notFound();
|
||||
|
||||
const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch(() => null);
|
||||
const details = await queryClient.fetchQuery(detailsQuery({ showId, showType })).catch((error) => {
|
||||
if (isMissing(error)) return null;
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
if (!details) return notFound();
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import { createShowMetadata, createShowPage } from '../../showPage';
|
||||
|
||||
export const revalidate = 86400;
|
||||
|
||||
export const generateStaticParams = async () => [];
|
||||
|
||||
export const generateMetadata = createShowMetadata('tv');
|
||||
|
||||
const SeriesPage = createShowPage('tv');
|
||||
|
||||
@@ -8,6 +8,7 @@ import Person from '@/components/Person';
|
||||
import personQuery from '@/data/queries/person';
|
||||
import { SITE_URL, TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
import { isMissing } from '@/lib/utils';
|
||||
|
||||
interface Props {
|
||||
params: { id: string };
|
||||
@@ -15,6 +16,8 @@ interface Props {
|
||||
|
||||
export const revalidate = 86400;
|
||||
|
||||
export const generateStaticParams = async () => [];
|
||||
|
||||
export const generateMetadata = async ({ params: { id } }: Props): Promise<Metadata> => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
@@ -36,15 +39,21 @@ export const generateMetadata = async ({ params: { id } }: Props): Promise<Metad
|
||||
url: `/person/${id}`
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
return notFound();
|
||||
} catch (error) {
|
||||
if (isMissing(error)) return notFound();
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const PersonPage: FC<Props> = async ({ params: { id } }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const profile = await queryClient.fetchQuery(personQuery({ personId: id })).catch(() => null);
|
||||
const profile = await queryClient.fetchQuery(personQuery({ personId: id })).catch((error) => {
|
||||
if (isMissing(error)) return null;
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
if (!profile) return notFound();
|
||||
|
||||
|
||||
Reference in new issue
Block a user