Skip to content

Commit bc72cca

Browse files
committed
Change page purging to all instead of locale specific
1 parent 3f44d7a commit bc72cca

File tree

5 files changed

+30
-60
lines changed

5 files changed

+30
-60
lines changed

src/collections/Media.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,10 @@ export const Media: CollectionConfig = {
5959
})
6060

6161
if (isThumbnail.totalDocs > 0) {
62-
if (req.locale === 'all') {
63-
routing.locales.forEach((locale) => {
64-
revalidatePath(`/${locale}/projects`)
65-
purgeRoute(`${locale}/projects`)
66-
})
67-
} else {
68-
revalidatePath(`/${req.locale}/projects`)
69-
purgeRoute(`${req.locale}/projects`)
70-
}
62+
routing.locales.forEach((locale) => {
63+
revalidatePath(`/${locale}/projects`)
64+
purgeRoute(`${locale}/projects`)
65+
})
7166
}
7267
},
7368
],

src/collections/Projects.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,24 @@ export const Projects: CollectionConfig = {
274274
},
275275
hooks: {
276276
afterChange: [
277-
async ({ doc, req }) => {
277+
async ({ doc }) => {
278278
// Ignore draft updates
279279
// Only revalidate cache when a document has been published
280280
if (doc._status === 'published') {
281-
const updatedLocale = req.locale
282281
const updateURL = `/projects/${doc.id}`
283282

284-
// If all locales were updated then revalidate all languages otherwise only the updated locale
285-
if (updatedLocale === 'all')
286-
routing.locales.forEach(async (locale) => {
287-
revalidatePath(`/${locale}${updateURL}`)
288-
await purgeURL(`${locale}${updateURL}`) // Purge nginx cache
289-
290-
// Revalidate projects page in case name or thumbnail were changed
291-
revalidatePath(`/${locale}/projects`)
292-
await purgeURL(`${locale}/projects`)
293-
})
294-
else {
295-
revalidatePath(`/${updatedLocale}${updateURL}`)
296-
await purgeURL(`${updatedLocale}${updateURL}`)
283+
// Revalidate all locales since when making changes not related
284+
// to localization it only updates that locale instead of all.
285+
// Revalidating everything (even if not needed) is an ease of use
286+
// tradeoff.
287+
routing.locales.forEach(async (locale) => {
288+
revalidatePath(`/${locale}${updateURL}`)
289+
await purgeURL(`${locale}${updateURL}`) // Purge nginx cache
297290

298291
// Revalidate projects page in case name or thumbnail were changed
299-
revalidatePath(`/${updatedLocale}/projects`)
300-
await purgeURL(`${updatedLocale}/projects`)
301-
}
292+
revalidatePath(`/${locale}/projects`)
293+
await purgeURL(`${locale}/projects`)
294+
})
302295
}
303296
},
304297
],

src/globals/Conclusion.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,12 @@ export const Conclusion: GlobalConfig = {
5555
},
5656
hooks: {
5757
afterChange: [
58-
async ({ req, doc }) => {
58+
async ({ doc }) => {
5959
if (doc._status === 'published') {
60-
const updatedLocale = req.locale
61-
if (updatedLocale === 'all')
62-
routing.locales.map(async (locale) => {
63-
revalidatePath(`/${locale}/conclusion`)
64-
await purgeRoute(`${locale}/conclusion`)
65-
})
66-
else {
67-
revalidatePath(`/${updatedLocale}/conclusion`)
68-
await purgeRoute(`${updatedLocale}/conclusion`)
69-
}
60+
routing.locales.map(async (locale) => {
61+
revalidatePath(`/${locale}/conclusion`)
62+
await purgeRoute(`${locale}/conclusion`)
63+
})
7064
}
7165
},
7266
],

src/globals/MainPage.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,12 @@ const MainPage: GlobalConfig = {
228228
},
229229
hooks: {
230230
afterChange: [
231-
async ({ req, doc }) => {
231+
async ({ doc }) => {
232232
if (doc._status === 'published') {
233-
const updatedLocale = req.locale
234-
if (updatedLocale === 'all')
235-
routing.locales.map(async (locale) => {
236-
revalidatePath(`/${locale}`)
237-
await purgeRoute(`${locale}`)
238-
})
239-
else {
240-
revalidatePath(`/${updatedLocale}`)
241-
await purgeRoute(`${updatedLocale}`)
242-
}
233+
routing.locales.map(async (locale) => {
234+
revalidatePath(`/${locale}`)
235+
await purgeRoute(`${locale}`)
236+
})
243237
}
244238
},
245239
],

src/globals/Sculptures.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,12 @@ export const Sculptures: GlobalConfig = {
101101
},
102102
hooks: {
103103
afterChange: [
104-
async ({ req, doc }) => {
104+
async ({ doc }) => {
105105
if (doc._status === 'published') {
106-
const updatedLocale = req.locale
107-
if (updatedLocale === 'all')
108-
routing.locales.map(async (locale) => {
109-
revalidatePath(`/${locale}/sculptures`)
110-
await purgeRoute(`${locale}/sculptures`)
111-
})
112-
else {
113-
revalidatePath(`/${updatedLocale}/sculptures`)
114-
await purgeRoute(`${updatedLocale}/sculptures`)
115-
}
106+
routing.locales.map(async (locale) => {
107+
revalidatePath(`/${locale}/sculptures`)
108+
await purgeRoute(`${locale}/sculptures`)
109+
})
116110
}
117111
},
118112
],

0 commit comments

Comments
 (0)