diff --git a/models/common.ts b/models/common.ts index c50882b..610e2f2 100644 --- a/models/common.ts +++ b/models/common.ts @@ -77,8 +77,12 @@ export default class Model extends TypeORM.BaseEntity { async destroy() { const id = (this as any).id; await TypeORM.getManager().remove(this); - if ((this.constructor as typeof Model).cache) { - cacheSet(this.constructor.name, id, null); + await (this.constructor as typeof Model).deleteFromCache(id); + } + + static async deleteFromCache(id) { + if (this.cache) { + cacheSet(this.name, id, null); } } diff --git a/models/problem.ts b/models/problem.ts index a2b5c1b..ccc6b48 100644 --- a/models/problem.ts +++ b/models/problem.ts @@ -536,6 +536,7 @@ export default class Problem extends Model { let oldTestdataDir = this.getTestdataPath(), oldTestdataZip = this.getTestdataArchivePath(); + const oldID = this.id; this.id = id; // Move testdata @@ -549,6 +550,9 @@ export default class Problem extends Model { } await this.save(); + + await Problem.deleteFromCache(oldID); + await problemTagCache.del(oldID); } async delete() {