Browse Source

Remove it from cache after change a problem's id

pull/6/head
Menci 6 years ago
parent
commit
ed13aa149d
  1. 8
      models/common.ts
  2. 4
      models/problem.ts

8
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);
}
}

4
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() {

Loading…
Cancel
Save