diff --git a/lib/commands/show.js b/lib/commands/show.js index 7c66204a..56b9341e 100644 --- a/lib/commands/show.js +++ b/lib/commands/show.js @@ -152,14 +152,20 @@ 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); + else + log.printf('* 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); 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) { 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