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:
parent
e8e37fd094
commit
6e1dfeb76b
2 changed files with 21 additions and 2 deletions
5
.changeset/ninety-monkeys-complain.md
Normal file
5
.changeset/ninety-monkeys-complain.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Clear content layer cache when astro version changes
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue