From bee4805d0d946bd6ec46afad7ef01e15d0e90dee Mon Sep 17 00:00:00 2001 From: t123yh Date: Tue, 22 Aug 2017 22:01:51 +0800 Subject: [PATCH] Avoid repetitive load relationship. --- models/judge_state.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/judge_state.js b/models/judge_state.js index 1a5dab2..dc94211 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -101,8 +101,12 @@ class JudgeState extends Model { } async loadRelationships() { - this.user = await User.fromID(this.user_id); - if (this.problem_id) this.problem = await Problem.fromID(this.problem_id); + if (!this.user) { + this.user = await User.fromID(this.user_id); + } + if (!this.problem) { + if (this.problem_id) this.problem = await Problem.fromID(this.problem_id); + } } async isAllowedVisitBy(user) {