perf: add Prisma query caching, ISR for news pages, and aggressive SW caching
- Introduce redis-backed Prisma query cache (prisma-cache.ts) with per-model TTL - Replace force-dynamic with revalidate=60 + generateStaticParams on news/[slug] - Wrap article query with Redis cache (60s TTL) - Upgrade service worker to v2 with dedicated API cache and stale-while-revalidate for static assets
This commit is contained in:
1 parent
d5e3bc7875
commit
c8ccbe1f42
3 files changed
+135
-30
No files matched your search
@@ -9,9 +9,21 @@ import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { excerpt } from "@/lib/format";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { cacheQuery } from "@/lib/prisma-cache";
|
||||
import { sanitize } from "@/lib/sanitize";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const revalidate = 60;
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const slugs = await prisma.websiteArticles
|
||||
.findMany({
|
||||
select: { slug: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 20,
|
||||
})
|
||||
.catch(() => []);
|
||||
return slugs.map((a) => ({ slug: a.slug }));
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
@@ -55,21 +67,27 @@ export default async function ArticlePage({
|
||||
const { slug } = await params;
|
||||
const t = await getTranslations("pages.article");
|
||||
|
||||
const article = await prisma.websiteArticles
|
||||
.findUnique({
|
||||
where: { slug },
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
shortStory: true,
|
||||
fullStory: true,
|
||||
image: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
})
|
||||
.catch(() => null);
|
||||
const article = await cacheQuery(
|
||||
"websiteArticles",
|
||||
"findUnique",
|
||||
{ slug },
|
||||
() =>
|
||||
prisma.websiteArticles
|
||||
.findUnique({
|
||||
where: { slug },
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
shortStory: true,
|
||||
fullStory: true,
|
||||
image: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
})
|
||||
.catch(() => null),
|
||||
);
|
||||
if (!article) notFound();
|
||||
|
||||
const articleId = article.id;
|
||||
|
||||
Reference in new issue
Block a user