Skip to content

Commit

Permalink
fix: clear content layer cache if astro version changes (#12126)
Browse files Browse the repository at this point in the history
* fix: clear content layer cache if astro version changes

* changeset
  • Loading branch information
ascorbic authored Oct 4, 2024
1 parent e8e37fd commit 6e1dfeb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-monkeys-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Clear content layer cache when astro version changes
18 changes: 16 additions & 2 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,27 @@ export class ContentLayer {
const { digest: currentConfigDigest } = contentConfig.config;
this.#lastConfigDigest = currentConfigDigest;

let shouldClear = false;
const previousConfigDigest = await this.#store.metaStore().get('config-digest');
const previousAstroVersion = await this.#store.metaStore().get('astro-version');
if (currentConfigDigest && previousConfigDigest !== currentConfigDigest) {
logger.info('Content config changed, clearing cache');
logger.info('Content config changed');
shouldClear = true;
}
if (process.env.ASTRO_VERSION && previousAstroVersion !== process.env.ASTRO_VERSION) {
logger.info('Astro version changed');
shouldClear = true;
}
if (shouldClear) {
logger.info('Clearing content store');
this.#store.clearAll();
}
if (process.env.ASTRO_VERSION) {
await this.#store.metaStore().set('astro-version', process.env.ASTRO_VERSION);
}
if (currentConfigDigest) {
await this.#store.metaStore().set('config-digest', currentConfigDigest);
}

await Promise.all(
Object.entries(contentConfig.config.collections).map(async ([name, collection]) => {
if (collection.type !== CONTENT_LAYER_TYPE) {
Expand Down

0 comments on commit 6e1dfeb

Please sign in to comment.