mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add lock for system cache (#12017)
* Add lock for system cache * Add lock when forcing a flush * Simplify code Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import SchemaInspector from '@directus/schema';
|
||||
import { Knex } from 'knex';
|
||||
import { getCache } from '../cache';
|
||||
import { getCache, clearSystemCache } from '../cache';
|
||||
import { ALIAS_TYPES } from '../constants';
|
||||
import getDatabase, { getSchemaInspector } from '../database';
|
||||
import { systemCollectionRows } from '../database/system-data/collections';
|
||||
@@ -141,7 +141,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return payload.collection;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return collections;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return collectionKey;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return collectionKeys;
|
||||
}
|
||||
@@ -455,7 +455,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return collectionKey;
|
||||
}
|
||||
@@ -484,7 +484,7 @@ export class CollectionsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return collectionKeys;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import SchemaInspector from '@directus/schema';
|
||||
import { Knex } from 'knex';
|
||||
import { Column } from 'knex-schema-inspector/dist/types/column';
|
||||
import { getCache } from '../cache';
|
||||
import { getCache, clearSystemCache } from '../cache';
|
||||
import { ALIAS_TYPES } from '../constants';
|
||||
import getDatabase, { getSchemaInspector } from '../database';
|
||||
import { systemFieldRows } from '../database/system-data/fields/';
|
||||
@@ -298,7 +298,7 @@ export class FieldsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
}
|
||||
|
||||
async updateField(collection: string, field: RawField): Promise<string> {
|
||||
@@ -366,7 +366,7 @@ export class FieldsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
emitter.emitAction(
|
||||
`fields.update`,
|
||||
@@ -494,7 +494,7 @@ export class FieldsService {
|
||||
await this.cache.clear();
|
||||
}
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
emitter.emitAction(
|
||||
'fields.delete',
|
||||
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
import { Knex } from 'knex';
|
||||
import { flatten, get, mapKeys, merge, set, uniq, pick, transform, isObject, omit } from 'lodash';
|
||||
import ms from 'ms';
|
||||
import { getCache } from '../cache';
|
||||
import { getCache, clearSystemCache } from '../cache';
|
||||
import getDatabase from '../database';
|
||||
import env from '../env';
|
||||
import { BaseException } from '@directus/shared/exceptions';
|
||||
@@ -2033,10 +2033,10 @@ export class GraphQLService {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
const { cache, systemCache } = getCache();
|
||||
const { cache } = getCache();
|
||||
|
||||
await cache?.clear();
|
||||
await systemCache.clear();
|
||||
await clearSystemCache();
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AbstractServiceOptions, Item, PrimaryKey, MutationOptions } from '../ty
|
||||
import { Query, PermissionsAction } from '@directus/shared/types';
|
||||
import { filterItems } from '../utils/filter-items';
|
||||
import Keyv from 'keyv';
|
||||
import { getCache } from '../cache';
|
||||
import { getCache, clearSystemCache } from '../cache';
|
||||
|
||||
export class PermissionsService extends ItemsService {
|
||||
systemCache: Keyv<any>;
|
||||
@@ -80,61 +80,61 @@ export class PermissionsService extends ItemsService {
|
||||
|
||||
async createOne(data: Partial<Item>, opts?: MutationOptions) {
|
||||
const res = await super.createOne(data, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async createMany(data: Partial<Item>[], opts?: MutationOptions) {
|
||||
const res = await super.createMany(data, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async updateByQuery(query: Query, data: Partial<Item>, opts?: MutationOptions) {
|
||||
const res = await super.updateByQuery(query, data, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async updateOne(key: PrimaryKey, data: Partial<Item>, opts?: MutationOptions) {
|
||||
const res = await super.updateOne(key, data, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async updateMany(keys: PrimaryKey[], data: Partial<Item>, opts?: MutationOptions) {
|
||||
const res = await super.updateMany(keys, data, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async upsertOne(payload: Partial<Item>, opts?: MutationOptions) {
|
||||
const res = await super.upsertOne(payload, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async upsertMany(payloads: Partial<Item>[], opts?: MutationOptions) {
|
||||
const res = await super.upsertMany(payloads, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async deleteByQuery(query: Query, opts?: MutationOptions) {
|
||||
const res = await super.deleteByQuery(query, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async deleteOne(key: PrimaryKey, opts?: MutationOptions) {
|
||||
const res = await super.deleteOne(key, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
|
||||
async deleteMany(keys: PrimaryKey[], opts?: MutationOptions) {
|
||||
const res = await super.deleteMany(keys, opts);
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import SchemaInspector from '@directus/schema';
|
||||
import { ForeignKey } from 'knex-schema-inspector/dist/types/foreign-key';
|
||||
import getDatabase, { getSchemaInspector } from '../database';
|
||||
import { getDefaultIndexName } from '../utils/get-default-index-name';
|
||||
import { getCache } from '../cache';
|
||||
import { getCache, clearSystemCache } from '../cache';
|
||||
import Keyv from 'keyv';
|
||||
import { AbstractServiceOptions } from '../types';
|
||||
|
||||
@@ -201,7 +201,7 @@ export class RelationsService {
|
||||
await relationsItemService.createOne(metaRow);
|
||||
});
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +279,7 @@ export class RelationsService {
|
||||
}
|
||||
});
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +324,7 @@ export class RelationsService {
|
||||
}
|
||||
});
|
||||
|
||||
await this.systemCache.clear();
|
||||
await clearSystemCache();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user