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() { async destroy() {
const id = (this as any).id; const id = (this as any).id;
await TypeORM.getManager().remove(this); await TypeORM.getManager().remove(this);
if ((this.constructor as typeof Model).cache) { await (this.constructor as typeof Model).deleteFromCache(id);
cacheSet(this.constructor.name, id, null); }
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(); let oldTestdataDir = this.getTestdataPath(), oldTestdataZip = this.getTestdataArchivePath();
const oldID = this.id;
this.id = id; this.id = id;
// Move testdata // Move testdata
@ -549,6 +550,9 @@ export default class Problem extends Model {
} }
await this.save(); await this.save();
await Problem.deleteFromCache(oldID);
await problemTagCache.del(oldID);
} }
async delete() { async delete() {

Loading…
Cancel
Save