Skip to content

Commit 4df823b

Browse files
authored
Merge pull request #602 from CodingCatDev/feature/nextjs-caching-optimization
perf: implement ISR caching with tag-based revalidation
2 parents b8cc013 + f25da91 commit 4df823b

File tree

46 files changed

+247
-966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+247
-966
lines changed

app/(main)/(author)/author/[slug]/page.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
AuthorQueryWithRelatedResult,
1010
} from "@/sanity/types";
1111
import { sanityFetch } from "@/sanity/lib/live";
12+
import { client } from "@/sanity/lib/client";
1213
import { authorQuery, authorQueryWithRelated } from "@/sanity/lib/queries";
1314
import { resolveOpenGraphImage } from "@/sanity/lib/utils";
1415
import CoverMedia from "@/components/cover-media";
@@ -19,6 +20,8 @@ import UserRelated from "@/components/user-related";
1920

2021
type Params = Promise<{ slug: string }>;
2122

23+
export const revalidate = 3600;
24+
2225
export async function generateMetadata(
2326
{ params }: { params: Params },
2427
parent: ResolvingMetadata,
@@ -45,6 +48,13 @@ export async function generateMetadata(
4548
} satisfies Metadata;
4649
}
4750

51+
export async function generateStaticParams() {
52+
const slugs = await client.fetch<string[]>(
53+
groq`*[_type == "author" && defined(slug.current)].slug.current`,
54+
);
55+
return slugs.map((slug) => ({ slug }));
56+
}
57+
4858
export default async function AuthorPage({ params }: { params: Params }) {
4959
const { slug } = await params;
5060

app/(main)/(author)/authors/page/[num]/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
import MoreContent from "@/components/more-content";
22
import type { DocCountResult } from "@/sanity/types";
33
import { sanityFetch } from "@/sanity/lib/live";
4+
import { client } from "@/sanity/lib/client";
45

56
import PaginateList from "@/components/paginate-list";
67
import { docCount } from "@/sanity/lib/queries";
8+
import { groq } from "next-sanity";
79

810
const LIMIT = 10;
911

1012
type Params = Promise<{ num: string }>;
1113

14+
export const revalidate = 60;
15+
16+
export async function generateStaticParams() {
17+
const count = await client.fetch<number>(
18+
groq`count(*[_type == "author" && defined(slug.current)])`,
19+
);
20+
const perPage = LIMIT;
21+
const pages = Math.ceil(count / perPage);
22+
return Array.from({ length: pages }, (_, i) => ({ num: String(i + 1) }));
23+
}
24+
1225
export default async function Page({ params }: { params: Params }) {
1326
const { num } = await params;
1427

app/(main)/(course)/course/[courseSlug]/lesson/[lessonSlug]/lesson-client-only.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/(main)/(course)/course/[courseSlug]/lesson/[lessonSlug]/lesson-complete.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

app/(main)/(course)/course/[courseSlug]/lesson/[lessonSlug]/lesson-panel.tsx

Lines changed: 0 additions & 153 deletions
This file was deleted.

app/(main)/(course)/course/[courseSlug]/lesson/[lessonSlug]/nav-lesson.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)