Repository: withastro/astro
File: packages/astro/src/content/content-layer.ts (TypeScript)

Code before:
				...this.#settings.dataEntryTypes,
			] as Array<ContentEntryType>),
		};
	}

	/**
	 * Enqueues a sync job that runs the `load()` method of each collection's loader, which will load the data and save it in the data store.
	 * The loader itself is responsible for deciding whether this will clear and reload the full collection, or
	 * perform an incremental update. After the data is loaded, the data store is written to disk. Jobs are queued,
	 * so that only one sync can run at a time. The function returns a promise that resolves when this sync job is complete.
	 */

	sync(options: RefreshContentOptions = {}): Promise<void> {
		return this.#queue.add(() => this.#doSync(options));
	}

	async #doSync(options: RefreshContentOptions) {
		const contentConfig = globalContentConfigObserver.get();
		const logger = this.#logger.forkIntegrationLogger('content');
		if (contentConfig?.status !== 'loaded') {
			logger.debug('Content config not loaded, skipping sync');
			return;
		}

		logger.info('Syncing content');
		const { vite: _vite, integrations: _integrations, adapter: _adapter, ...hashableConfig } = this.#settings.config;
		const generateDigest = await this.#getGenerateDigest()
		
		const astroConfigDigest = generateDigest(hashableConfig);

		const { digest: currentConfigDigest } = contentConfig.config;
		this.#lastConfigDigest = currentConfigDigest;

		let shouldClear = false;
		const previousConfigDigest = await this.#store.metaStore().get('config-digest');
		const previousAstroConfigDigest = await this.#store.metaStore().get('astro-config-digest');
		const previousAstroVersion = await this.#store.metaStore().get('astro-version');

		if (astroConfigDigest && previousAstroConfigDigest !== astroConfigDigest) {
			logger.info('Astro config changed');
			shouldClear = true;
		}

		if (currentConfigDigest && previousConfigDigest !== currentConfigDigest) {
			logger.info('Content config changed');
			shouldClear = true;
		}
		if (process.env.ASTRO_VERSION && previousAstroVersion !== process.env.ASTRO_VERSION) {
			logger.info('Astro version changed');
			shouldClear = true;
		}

Review comment (suggestion):
I think we should **pick** the keys that we want to hash. This is safer in the long run, so we can add new configuration (even functions) without risking to breaking this code. 

For example, the fonts RFC will add some runtime code for loading custom providers, and I doubt that we can create a hash from them. 

Code after:
				...this.#settings.dataEntryTypes,
			] as Array<ContentEntryType>),
		};
	}

	/**
	 * Enqueues a sync job that runs the `load()` method of each collection's loader, which will load the data and save it in the data store.
	 * The loader itself is responsible for deciding whether this will clear and reload the full collection, or
	 * perform an incremental update. After the data is loaded, the data store is written to disk. Jobs are queued,
	 * so that only one sync can run at a time. The function returns a promise that resolves when this sync job is complete.
	 */

	sync(options: RefreshContentOptions = {}): Promise<void> {
		return this.#queue.add(() => this.#doSync(options));
	}

	async #doSync(options: RefreshContentOptions) {
		const contentConfig = globalContentConfigObserver.get();
		const logger = this.#logger.forkIntegrationLogger('content');
		if (contentConfig?.status !== 'loaded') {
			logger.debug('Content config not loaded, skipping sync');
			return;
		}

		logger.info('Syncing content');
		const {
			vite: _vite,
			integrations: _integrations,
			adapter: _adapter,
			...hashableConfig
		} = this.#settings.config;

		const astroConfigDigest = safeStringify(hashableConfig);

		const { digest: currentConfigDigest } = contentConfig.config;
		this.#lastConfigDigest = currentConfigDigest;

		let shouldClear = false;
		const previousConfigDigest = await this.#store.metaStore().get('content-config-digest');
		const previousAstroConfigDigest = await this.#store.metaStore().get('astro-config-digest');
		const previousAstroVersion = await this.#store.metaStore().get('astro-version');

		if (previousAstroConfigDigest && previousAstroConfigDigest !== astroConfigDigest) {
			logger.info('Astro config changed');
			shouldClear = true;
		}

		if (currentConfigDigest && previousConfigDigest !== currentConfigDigest) {
			logger.info('Content config changed');
			shouldClear = true;
		}