Skip to content

Commit 24ea979

Browse files
committed
Optimize caching and deployment workflow
Use five-minute revalidation for published content, posts, and sitemaps, while pre-rendering known article routes. Make Netlify deployments manual and cancel superseded runs.
1 parent 66f2538 commit 24ea979

7 files changed

Lines changed: 20 additions & 43 deletions

File tree

.github/workflows/deploy-to-netlify.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: Deploy to Netlify
22

33
on:
4-
push:
5-
branches: [main]
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: netlify-production-${{ github.repository }}
8+
cancel-in-progress: true
69

710
permissions:
811
contents: read
@@ -41,9 +44,6 @@ jobs:
4144
restore-keys: |
4245
${{ runner.os }}-nextjs-
4346
44-
- name: Build project
45-
run: npm run build
46-
4747
- name: Install Netlify CLI
4848
run: npm install -g netlify-cli
4949

app/[...not_found]/page.tsx

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

app/account/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ export default function AccountPage() {
490490
try {
491491
await uploadBytes(avatarRef, sanitized.blob, {
492492
contentType: sanitized.contentType,
493-
cacheControl: "public,max-age=3600",
493+
cacheControl: "public,max-age=300",
494494
});
495495
} finally {
496496
URL.revokeObjectURL(sanitized.previewUrl);

app/posts/[title]/opengraph-image/route.ts

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

app/posts/[title]/page.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ type RouteParams = {
2424
title: string;
2525
};
2626

27-
export const dynamic = "force-dynamic";
27+
export const revalidate = 300;
2828
export const dynamicParams = true;
2929

30+
export async function generateStaticParams() {
31+
const articles = await getPublishedArticles();
32+
return articles.map((article) => ({
33+
title: article.slug,
34+
}));
35+
}
36+
3037
function buildKeywords(
3138
articleTitle: string,
3239
articleDescription: string,

app/sitemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MetadataRoute } from "next";
22
import { buildTopicSummaries, getAllAuthors, getPublishedArticles } from "@/lib/content";
33
import { absoluteUrl } from "@/lib/seo";
44

5-
export const dynamic = "force-dynamic";
5+
export const revalidate = 300;
66

77
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
88
// Static routes

lib/content.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,7 @@ function normalizeRouteSlug(slug: string) {
365365
}
366366
}
367367

368-
async function getPublishedArticleDocuments(
369-
revalidateSeconds: number | false = 300,
370-
): Promise<ContentDocument[]> {
368+
async function getPublishedArticleDocuments(): Promise<ContentDocument[]> {
371369
const { apiKey, projectId } = getRequiredFirebaseConfig();
372370
const params = new URLSearchParams({ key: apiKey });
373371
const response = await fetch(
@@ -389,9 +387,7 @@ async function getPublishedArticleDocuments(
389387
},
390388
},
391389
}),
392-
...(revalidateSeconds === false
393-
? { cache: "no-store" as const }
394-
: { next: { revalidate: revalidateSeconds } }),
390+
next: { revalidate: 300 },
395391
},
396392
);
397393

@@ -548,12 +544,9 @@ export async function getPublishedArticleBySlug(slug: string) {
548544
const authors = await getAllAuthors();
549545
const authorLookup = createAuthorLookup(authors);
550546
const documents = await getPublishedArticleDocuments();
551-
const cached = documents.find((entry) => entry.data.slug === normalizedSlug);
552-
const document =
553-
cached ||
554-
(await getPublishedArticleDocuments(false)).find(
555-
(entry) => entry.data.slug === normalizedSlug,
556-
);
547+
const document = documents.find(
548+
(entry) => entry.data.slug === normalizedSlug,
549+
);
557550

558551
if (!document) return null;
559552

0 commit comments

Comments
 (0)