From 6e1dfeb76bec09d24928bab798c6ad3280f42e84 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 4 Oct 2024 15:10:39 +0100 Subject: [PATCH] fix: clear content layer cache if astro version changes (#12126) * fix: clear content layer cache if astro version changes * changeset --- .changeset/ninety-monkeys-complain.md | 5 +++++ packages/astro/src/content/content-layer.ts | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/ninety-monkeys-complain.md diff --git a/.changeset/ninety-monkeys-complain.md b/.changeset/ninety-monkeys-complain.md new file mode 100644 index 000000000000..c8a06da1f37f --- /dev/null +++ b/.changeset/ninety-monkeys-complain.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Clear content layer cache when astro version changes diff --git a/packages/astro/src/content/content-layer.ts b/packages/astro/src/content/content-layer.ts index c07d5dd55f8a..b2729ce4dd72 100644 --- a/packages/astro/src/content/content-layer.ts +++ b/packages/astro/src/content/content-layer.ts @@ -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) {