Flush cache when applying diff (#18986)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
ian
2023-06-27 21:13:54 +08:00
committed by GitHub
parent 615c827609
commit 757a5914af
3 changed files with 9 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/api": patch
---
Ensured all caches are flushed when applying diff

View File

@@ -86,7 +86,7 @@ export async function clearSystemCache(opts?: {
forced?: boolean | undefined;
autoPurgeCache?: false | undefined;
}): Promise<void> {
const { systemCache, localSchemaCache, lockCache } = getCache();
const { systemCache, localSchemaCache, lockCache, sharedSchemaCache } = getCache();
// Flush system cache when forced or when system cache lock not set
if (opts?.forced || !(await lockCache.get('system-cache-lock'))) {
@@ -95,6 +95,7 @@ export async function clearSystemCache(opts?: {
await lockCache.delete('system-cache-lock');
}
await sharedSchemaCache.clear();
await localSchemaCache.clear();
messenger.publish('schemaChanged', { autoPurgeCache: opts?.autoPurgeCache });
}

View File

@@ -3,7 +3,7 @@ import type { Diff, DiffDeleted, DiffNew } from 'deep-diff';
import deepDiff from 'deep-diff';
import type { Knex } from 'knex';
import { cloneDeep, merge, set } from 'lodash-es';
import { clearSystemCache } from '../cache.js';
import { flushCaches } from '../cache.js';
import { getHelpers } from '../database/helpers/index.js';
import getDatabase from '../database/index.js';
import emitter from '../emitter.js';
@@ -324,7 +324,7 @@ export async function applyDiff(
await helpers.schema.postColumnChange();
}
await clearSystemCache();
await flushCaches();
if (nestedActionEvents.length > 0) {
const updatedSchema = await getSchema({ database, bypassCache: true });