Skip to content

Commit 1c0ccb0

Browse files
Vigilansjdneo
authored andcommitted
Bug fix & Prepare for preview markdown webview (#2)
1 parent ca7487a commit 1c0ccb0

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

lib/commands/submit.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,20 @@ cmd.handler = function(argv) {
6666
if (result.ok) {
6767
session.updateStat('ac', 1);
6868
session.updateStat('ac.set', problem.fid);
69-
if (result.runtime_percentile)
70-
printLine(result, 'Your runtime beats %d %% of %s submissions',
71-
result.runtime_percentile.toFixed(2), result.lang);
72-
else
73-
return log.warn('Failed to get runtime percentile.');
74-
if (result.memory && result.memory_percentile)
75-
printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)',
76-
result.memory_percentile.toFixed(2), result.lang, result.memory);
77-
else
78-
return log.warn('Failed to get memory percentile.');
69+
70+
(function () {
71+
if (result.runtime_percentile)
72+
printLine(result, 'Your runtime beats %d %% of %s submissions',
73+
result.runtime_percentile.toFixed(2), result.lang);
74+
else
75+
return log.warn('Failed to get runtime percentile.');
76+
if (result.memory && result.memory_percentile)
77+
printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)',
78+
result.memory_percentile.toFixed(2), result.lang, result.memory);
79+
else
80+
return log.warn('Failed to get memory percentile.');
81+
})();
82+
7983
// core.getSubmission({id: result.id}, function(e, submission) {
8084
// if (e || !submission || !submission.distributionChart)
8185
// return log.warn('Failed to get submission beat ratio.');

lib/plugins/cache.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ plugin.getProblem = function(problem, cb) {
2828
const k = h.KEYS.problem(problem);
2929
const _problem = cache.get(k);
3030
if (_problem) {
31-
log.debug('cache hit: ' + k + '.json');
32-
_.extendOwn(problem, _problem);
33-
return cb(null, problem);
31+
// Only hit description with html tags (<pre> always exists for presenting testcase)
32+
if (_problem.desc.includes("<pre>")) {
33+
log.debug('cache hit: ' + k + '.json');
34+
_.extendOwn(problem, _problem);
35+
return cb(null, problem);
36+
}
37+
log.debug('cache discarded for being no longer valid: ' + k + '.json');
3438
}
3539

3640
plugin.next.getProblem(problem, function(e, _problem) {

lib/plugins/leetcode.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,11 @@ plugin.getProblem = function(problem, cb) {
158158
problem.totalAC = JSON.parse(q.stats).totalAccepted;
159159
problem.totalSubmit = JSON.parse(q.stats).totalSubmission;
160160

161-
let content = q.translatedContent ? q.translatedContent : q.content;
162-
// Replace <sup/> with '^' as the power operator
163-
content = content.replace(/<\/sup>/gm, '').replace(/<sup>/gm, '^');
164-
problem.desc = he.decode(cheerio.load(content).root().text());
161+
const content = q.translatedContent ? q.translatedContent : q.content;
162+
// // Replace <sup/> with '^' as the power operator
163+
// content = content.replace(/<\/sup>/gm, '').replace(/<sup>/gm, '^');
164+
// problem.desc = he.decode(cheerio.load(content).root().text());
165+
problem.desc = content;
165166

166167
problem.templates = JSON.parse(q.codeDefinition);
167168
problem.testcase = q.sampleTestCase;

0 commit comments

Comments
 (0)