mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
bug fixes
This commit is contained in:
18 files changed
+90
-72
No files matched your search
@@ -5,7 +5,7 @@ import path from 'path';
|
||||
import AdmZip from 'adm-zip';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'js-yaml';
|
||||
import { pick } from 'lodash';
|
||||
import { keyBy, pick } from 'lodash';
|
||||
import { Filter, ObjectId } from 'mongodb';
|
||||
import type { Readable } from 'stream';
|
||||
import { ProblemConfigFile, ProblemType } from '@hydrooj/common';
|
||||
@@ -409,12 +409,7 @@ export class ProblemModel {
|
||||
const psdocs = await ProblemModel.getMultiStatus(
|
||||
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
|
||||
).toArray();
|
||||
const r: Record<string, ProblemStatusDoc> = {};
|
||||
for (const psdoc of psdocs) {
|
||||
r[psdoc.docId] = psdoc;
|
||||
r[`${psdoc.domainId}#${psdoc.docId}`] = psdoc;
|
||||
}
|
||||
return r;
|
||||
return keyBy(psdocs, 'docId');
|
||||
}
|
||||
|
||||
static async updateStatus(
|
||||
@@ -468,7 +463,7 @@ export class ProblemModel {
|
||||
throw new ValidationError('zip', null, e.message);
|
||||
}
|
||||
await new Promise((resolve, reject) => {
|
||||
zip.extractAllToAsync(tmpdir, true, (err) => {
|
||||
zip.extractAllToAsync(tmpdir, true, false, (err) => {
|
||||
if (err) reject(err);
|
||||
resolve(null);
|
||||
});
|
||||
|
||||
@@ -252,7 +252,7 @@ export default class RecordModel {
|
||||
RecordModel.collStat.deleteMany({ _id: { $in: rids } }),
|
||||
task.deleteMany({ rid: { $in: rids } }),
|
||||
]);
|
||||
await RecordModel.collHistory.insertMany(rdocs.map((rdoc) => ({
|
||||
await RecordModel.collHistory.insertMany(rdocs.filter((rdoc) => rdoc.judgeAt).map((rdoc) => ({
|
||||
...pick(rdoc, [
|
||||
'compilerTexts', 'judgeTexts', 'testCases', 'subtasks',
|
||||
'score', 'time', 'memory', 'status', 'judgeAt', 'judger',
|
||||
|
||||
@@ -178,7 +178,7 @@ async function cleanFiles() {
|
||||
}
|
||||
}
|
||||
|
||||
export function apply(ctx: Context) {
|
||||
export async function apply(ctx: Context) {
|
||||
ctx.inject(['worker'], (c) => {
|
||||
c.worker.addHandler('storage.prune', cleanFiles);
|
||||
});
|
||||
@@ -190,24 +190,21 @@ export function apply(ctx: Context) {
|
||||
]);
|
||||
await StorageModel.del(problemFiles.concat(contestFiles).concat(trainingFiles).map((i) => i.path));
|
||||
});
|
||||
|
||||
if (process.env.NODE_APP_INSTANCE !== '0') return;
|
||||
ctx.on('ready', async () => {
|
||||
await db.ensureIndexes(
|
||||
StorageModel.coll,
|
||||
{ key: { path: 1 }, name: 'path' },
|
||||
{ key: { path: 1, autoDelete: 1 }, sparse: true, name: 'autoDelete' },
|
||||
{ key: { link: 1 }, sparse: true, name: 'link' },
|
||||
);
|
||||
if (!await ScheduleModel.count({ type: 'schedule', subType: 'storage.prune' })) {
|
||||
await ScheduleModel.add({
|
||||
type: 'schedule',
|
||||
subType: 'storage.prune',
|
||||
executeAfter: moment().startOf('hour').toDate(),
|
||||
interval: [1, 'hour'],
|
||||
});
|
||||
}
|
||||
});
|
||||
await db.ensureIndexes(
|
||||
StorageModel.coll,
|
||||
{ key: { path: 1 }, name: 'path' },
|
||||
{ key: { path: 1, autoDelete: 1 }, sparse: true, name: 'autoDelete' },
|
||||
{ key: { link: 1 }, sparse: true, name: 'link' },
|
||||
);
|
||||
if (!await ScheduleModel.count({ type: 'schedule', subType: 'storage.prune' })) {
|
||||
await ScheduleModel.add({
|
||||
type: 'schedule',
|
||||
subType: 'storage.prune',
|
||||
executeAfter: moment().startOf('hour').toDate(),
|
||||
interval: [1, 'hour'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
global.Hydro.model.storage = StorageModel;
|
||||
|
||||
Reference in new issue
Block a user