From df66659c5f36289959f921e7105a58786a00ef51 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 8 May 2021 21:02:42 +0800 Subject: [PATCH] judge: also cache by last-modified --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/cases.ts | 10 ++++++---- packages/hydrojudge/src/hosts/hydro.ts | 4 ++-- packages/hydrojudge/src/service.ts | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 252f2e1c4..4293d303e 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.6.0", + "version": "2.6.1", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/cases.ts b/packages/hydrojudge/src/cases.ts index 4aa642bf6..09adc6389 100644 --- a/packages/hydrojudge/src/cases.ts +++ b/packages/hydrojudge/src/cases.ts @@ -55,8 +55,9 @@ async function read0(folder: string, files: string[], checkFile, cfg) { const data = REG.reg.exec(file); const c = { input: file, output: '', id: REG.id(data) }; for (const func of REG.output) { - c.output = func(data); - if (fs.existsSync(path.resolve(folder, c.output))) { + if (cfg.noOutputFile) c.output = '/dev/null'; + else c.output = func(data); + if (c.output === '/dev/null' || fs.existsSync(path.resolve(folder, c.output))) { cases.push(c); break; } @@ -114,8 +115,9 @@ async function read1(folder: string, files: string[], checkFile, cfg, rst) { const data = REG.reg.exec(file); const c = { input: file, output: '', id: REG.id(data) }; for (const func of REG.output) { - c.output = func(data); - if (fs.existsSync(path.resolve(folder, c.output))) { + if (cfg.noOutputFile) c.output = '/dev/null'; + else c.output = func(data); + if (c.output === '/dev/null' || fs.existsSync(path.resolve(folder, c.output))) { if (!subtask[REG.subtask(data)]) { subtask[REG.subtask(data)] = [{ time: parseTimeMS(cfg.time || '1s'), diff --git a/packages/hydrojudge/src/hosts/hydro.ts b/packages/hydrojudge/src/hosts/hydro.ts index 734eb26b0..f60cb8492 100644 --- a/packages/hydrojudge/src/hosts/hydro.ts +++ b/packages/hydrojudge/src/hosts/hydro.ts @@ -196,8 +196,8 @@ export default class Hydro { const allFiles = new Set(); for (const file of files) { allFiles.add(file.name); - version[file.name] = file.etag; - if (etags[file.name] !== file.etag) filenames.push(file.name); + version[file.name] = file.etag + file.lastModified; + if (etags[file.name] !== file.etag + file.lastModified) filenames.push(file.name); } for (const name in etags) { if (!allFiles.has(name)) await fs.rm(path.join(filePath, name)); diff --git a/packages/hydrojudge/src/service.ts b/packages/hydrojudge/src/service.ts index 1df16a54a..273f5d190 100644 --- a/packages/hydrojudge/src/service.ts +++ b/packages/hydrojudge/src/service.ts @@ -85,8 +85,8 @@ async function postInit() { const filenames = new Set(); for (const file of files) { filenames.add(file.name); - version[file.name] = file.etag; - if (etags[file.name] !== file.etag) { + version[file.name] = file.etag + file.lastModified; + if (etags[file.name] !== file.etag + file.lastModified) { await storage.get(`problem/${domainId}/${pid}/testdata/${file.name}`, path.join(filePath, file.name)); } }