clear item cache when permissions change (#18526)

* clear item cache when permissions change

* Create slow-timers-fold.md

* Add tests

---------

Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Brainslug
2023-05-11 19:18:40 +02:00
committed by GitHub
parent 51ec0b1453
commit 110413e473
5 changed files with 317 additions and 0 deletions

View File

@@ -82,36 +82,66 @@ export class PermissionsService extends ItemsService {
override async createOne(data: Partial<Item>, opts?: MutationOptions) {
const res = await super.createOne(data, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
override async createMany(data: Partial<Item>[], opts?: MutationOptions) {
const res = await super.createMany(data, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
override async updateBatch(data: Partial<Item>[], opts?: MutationOptions) {
const res = await super.updateBatch(data, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
override async updateMany(keys: PrimaryKey[], data: Partial<Item>, opts?: MutationOptions) {
const res = await super.updateMany(keys, data, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
override async upsertMany(payloads: Partial<Item>[], opts?: MutationOptions) {
const res = await super.upsertMany(payloads, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
override async deleteMany(keys: PrimaryKey[], opts?: MutationOptions) {
const res = await super.deleteMany(keys, opts);
await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
if (this.cache && opts?.autoPurgeCache !== false) {
await this.cache.clear();
}
return res;
}
}