From b5d99555295d8f5a72509a27b252c1369d5e3cfc Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 21 Apr 2019 15:29:17 +0800 Subject: [PATCH] Fix problem tagIDs cache --- models/problem.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/models/problem.ts b/models/problem.ts index 82f8b25..5d4f9b4 100644 --- a/models/problem.ts +++ b/models/problem.ts @@ -566,19 +566,19 @@ export default class Problem extends Model { } async getTags() { + let tagIDs; if (problemTagCache.has(this.id)) { - return problemTagCache.get(this.id); - } - - let maps = await ProblemTagMap.find({ - where: { - problem_id: this.id - } - }); - - let tagIDs = maps.map(x => x.tag_id); + tagIDs = problemTagCache.get(this.id); + } else { + let maps = await ProblemTagMap.find({ + where: { + problem_id: this.id + } + }); - problemTagCache.set(this.id, tagIDs); + tagIDs = maps.map(x => x.tag_id); + problemTagCache.set(this.id, tagIDs); + } let res = await (tagIDs as any).mapAsync(async tagID => { return ProblemTag.findById(tagID);