From fc866019fd56bced99d6114baf139b031c01b0c7 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Mon, 1 Apr 2019 19:51:56 +0800 Subject: [PATCH 1/3] Wrap submission result with anonymous function --- lib/commands/submit.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/commands/submit.js b/lib/commands/submit.js index 9deaaa82..123c121a 100644 --- a/lib/commands/submit.js +++ b/lib/commands/submit.js @@ -66,16 +66,20 @@ cmd.handler = function(argv) { if (result.ok) { session.updateStat('ac', 1); session.updateStat('ac.set', problem.fid); - if (result.runtime_percentile) - printLine(result, 'Your runtime beats %d %% of %s submissions', - result.runtime_percentile.toFixed(2), result.lang); - else - return log.warn('Failed to get runtime percentile.'); - if (result.memory && result.memory_percentile) - printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)', - result.memory_percentile.toFixed(2), result.lang, result.memory); - else - return log.warn('Failed to get memory percentile.'); + + (function () { + if (result.runtime_percentile) + printLine(result, 'Your runtime beats %d %% of %s submissions', + result.runtime_percentile.toFixed(2), result.lang); + else + return log.warn('Failed to get runtime percentile.'); + if (result.memory && result.memory_percentile) + printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)', + result.memory_percentile.toFixed(2), result.lang, result.memory); + else + return log.warn('Failed to get memory percentile.'); + })(); + // core.getSubmission({id: result.id}, function(e, submission) { // if (e || !submission || !submission.distributionChart) // return log.warn('Failed to get submission beat ratio.'); From 4e83dd1c777812db84ff8352324985b3486c6cc6 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Mon, 1 Apr 2019 19:53:22 +0800 Subject: [PATCH 2/3] Do not filter html tags after downloading problem --- lib/plugins/leetcode.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index bba96e6a..2e2ede83 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -158,10 +158,11 @@ plugin.getProblem = function(problem, cb) { problem.totalAC = JSON.parse(q.stats).totalAccepted; problem.totalSubmit = JSON.parse(q.stats).totalSubmission; - let content = q.translatedContent ? q.translatedContent : q.content; - // Replace with '^' as the power operator - content = content.replace(/<\/sup>/gm, '').replace(//gm, '^'); - problem.desc = he.decode(cheerio.load(content).root().text()); + const content = q.translatedContent ? q.translatedContent : q.content; + // // Replace with '^' as the power operator + // content = content.replace(/<\/sup>/gm, '').replace(//gm, '^'); + // problem.desc = he.decode(cheerio.load(content).root().text()); + problem.desc = content; problem.templates = JSON.parse(q.codeDefinition); problem.testcase = q.sampleTestCase; From 08886087da054051d8975438085a2ae1caa252b2 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Mon, 1 Apr 2019 19:53:39 +0800 Subject: [PATCH 3/3] Do not hit cached problem without html tag --- lib/plugins/cache.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/plugins/cache.js b/lib/plugins/cache.js index 677c6c84..90abed93 100644 --- a/lib/plugins/cache.js +++ b/lib/plugins/cache.js @@ -28,9 +28,13 @@ plugin.getProblem = function(problem, cb) { const k = h.KEYS.problem(problem); const _problem = cache.get(k); if (_problem) { - log.debug('cache hit: ' + k + '.json'); - _.extendOwn(problem, _problem); - return cb(null, problem); + // Only hit description with html tags (
 always exists for presenting testcase)
+    if (_problem.desc.includes("
")) {
+      log.debug('cache hit: ' + k + '.json');
+      _.extendOwn(problem, _problem);
+      return cb(null, problem);
+    }
+    log.debug('cache discarded for being no longer valid: ' + k + '.json');
   }
 
   plugin.next.getProblem(problem, function(e, _problem) {