judge: fix cache prune

This commit is contained in:
undefined committed 2021-04-02 13:14:03 +08:00
1 parent 43c4bfd8e7
commit ba2cbffbfd
3 files changed
+6 -4

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.4.16", "version": "2.4.17",
"os": [ "os": [
"linux" "linux"
], ],
+4 -2
View File
@@ -23,10 +23,10 @@ export = function main() {
for (const domain of domains) { for (const domain of domains) {
const domaindir = path.resolve(hostdir, domain); const domaindir = path.resolve(hostdir, domain);
if (!fs.statSync(domaindir).isDirectory()) continue; if (!fs.statSync(domaindir).isDirectory()) continue;
const problems = fs.readdirSync(domaindir); let problems = fs.readdirSync(domaindir);
for (const problem of problems) { for (const problem of problems) {
const problemdir = path.resolve(domaindir, problem); const problemdir = path.resolve(domaindir, problem);
if (!fs.statSync(problem).isDirectory()) continue; if (!fs.statSync(problemdir).isDirectory()) continue;
let lastUsage = 0; let lastUsage = 0;
if (fs.existsSync(path.resolve(problemdir, 'lastUsage'))) { if (fs.existsSync(path.resolve(problemdir, 'lastUsage'))) {
const content = fs.readFileSync(path.resolve(problemdir, 'lastUsage')).toString(); const content = fs.readFileSync(path.resolve(problemdir, 'lastUsage')).toString();
@@ -37,6 +37,8 @@ export = function main() {
cnt++; cnt++;
logger.info('Removed cache %s', problemdir); logger.info('Removed cache %s', problemdir);
} }
problems = fs.readdirSync(domaindir);
if (!problems.length) fs.removeSync(domaindir);
} }
} }
logger.info('Done! %d items deleted.', cnt); logger.info('Done! %d items deleted.', cnt);
+1 -1
View File
@@ -66,7 +66,7 @@ export class ProblemMainHandler extends ProblemHandler {
let sort: number[]; let sort: number[];
if (q) { if (q) {
path[1][1] = 'problem_main'; path[1][1] = 'problem_main';
path.push([q, null, null, true]); path.push([`${this.translate('Keyword')}: ${q}`, null, null, true]);
if (search) { if (search) {
const result = await search(domainId, q); const result = await search(domainId, q);
query.docId = { $in: result }; query.docId = { $in: result };