From 8938a595cb6a7335ae4d8d25372c1543a1d6f7bb Mon Sep 17 00:00:00 2001 From: Vigilans Date: Thu, 11 Apr 2019 17:21:18 +0800 Subject: [PATCH 1/4] Fetch question's `likes` and `dislikes` info --- lib/plugins/leetcode.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/plugins/leetcode.js b/lib/plugins/leetcode.js index 2e2ede83..1db2e00b 100644 --- a/lib/plugins/leetcode.js +++ b/lib/plugins/leetcode.js @@ -134,6 +134,8 @@ plugin.getProblem = function(problem, cb) { ' question(titleSlug: $titleSlug) {', ' content', ' stats', + ' likes', + ' dislikes', ' codeDefinition', ' sampleTestCase', ' enableRunCode', @@ -157,6 +159,8 @@ plugin.getProblem = function(problem, cb) { problem.totalAC = JSON.parse(q.stats).totalAccepted; problem.totalSubmit = JSON.parse(q.stats).totalSubmission; + problem.likes = q.likes; + problem.dislikes = q.dislikes; const content = q.translatedContent ? q.translatedContent : q.content; // // Replace with '^' as the power operator From 4b4916d078096000d8795fdf5b778ada7c7f7810 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Thu, 11 Apr 2019 17:25:23 +0800 Subject: [PATCH 2/4] Add `likes` and `dislikes` to problem desc --- lib/commands/show.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/commands/show.js b/lib/commands/show.js index 7c66204a..f3f67ad7 100644 --- a/lib/commands/show.js +++ b/lib/commands/show.js @@ -152,14 +152,18 @@ function showProblem(problem, argv) { log.printf('* %s', problem.category); log.printf('* %s (%s%%)', h.prettyLevel(problem.level), problem.percent.toFixed(2)); - if (filename) - log.printf('* Source Code: %s', chalk.yellow.underline(filename)); + if (problem.likes) + log.printf('* Likes: %s', problem.likes); + if (problem.dislikes) + log.printf('* Dislikes: %s', problem.dislikes); if (problem.totalAC) log.printf('* Total Accepted: %s', problem.totalAC); if (problem.totalSubmit) log.printf('* Total Submissions: %s', problem.totalSubmit); if (problem.testable && problem.testcase) log.printf('* Testcase Example: %s', chalk.yellow(util.inspect(problem.testcase))); + if (filename) + log.printf('* Source Code: %s', chalk.yellow.underline(filename)); log.info(); log.info(problem.desc); From 791cdcfa5b188a2e8f3dd5ff24637b31fbdfd9af Mon Sep 17 00:00:00 2001 From: Vigilans Date: Thu, 11 Apr 2019 17:36:01 +0800 Subject: [PATCH 3/4] Do not hit problem cache without full props --- lib/plugins/cache.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/plugins/cache.js b/lib/plugins/cache.js index 90abed93..3c2194e7 100644 --- a/lib/plugins/cache.js +++ b/lib/plugins/cache.js @@ -28,13 +28,20 @@ plugin.getProblem = function(problem, cb) { const k = h.KEYS.problem(problem); const _problem = cache.get(k); if (_problem) { - // Only hit description with html tags (
 always exists for presenting testcase)
-    if (_problem.desc.includes("
")) {
+    // do not hit problem without html tags in desc (
 always exists for presenting testcase)
+    if (!_problem.desc.includes("
")) {
+      log.debug('cache discarded for being no longer valid: ' + k + '.json');
+    }
+    // do not hit problem without likes & dislikes (logic will be improved in new lib)
+    else if (!['likes', 'dislikes'].every(p => p in _problem)) {
+      log.debug('cache discarded for being too old: ' + k + '.json');
+    }
+    // cache hit
+    else {
       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) {

From afc5cd69dac013c37e0ae4b1051dc5933799cf6a Mon Sep 17 00:00:00 2001
From: Vigilans 
Date: Thu, 11 Apr 2019 18:44:21 +0800
Subject: [PATCH 4/4] Leetcode-cn DOES NOT have `dislike` data

---
 lib/commands/show.js | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/commands/show.js b/lib/commands/show.js
index f3f67ad7..56b9341e 100644
--- a/lib/commands/show.js
+++ b/lib/commands/show.js
@@ -156,6 +156,8 @@ function showProblem(problem, argv) {
     log.printf('* Likes:    %s', problem.likes);
   if (problem.dislikes)
     log.printf('* Dislikes: %s', problem.dislikes);
+  else
+    log.printf('* Dislikes: -');
   if (problem.totalAC)
     log.printf('* Total Accepted:    %s', problem.totalAC);
   if (problem.totalSubmit)