0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-24 22:46:02 -05:00

fix: clear content layer cache if astro version changes (#12126)

* fix: clear content layer cache if astro version changes

* changeset
This commit is contained in:
Matt Kane 2024-10-04 15:10:39 +01:00 committed by GitHub
parent e8e37fd094
commit 6e1dfeb76b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Clear content layer cache when astro version changes

View file

@ -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) {