mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
problem pretest
This commit is contained in:
1 parent
dd5a212422
commit
554698189c
17 files changed
+127
-57
No files matched your search
+17
-6
@@ -19,6 +19,7 @@ async function add(domainId, data, addTask = true) {
|
||||
score: 0,
|
||||
time: 0,
|
||||
memory: 0,
|
||||
hidden: false,
|
||||
rejudged: false,
|
||||
judgeTexts: [],
|
||||
compilerTexts: [],
|
||||
@@ -31,15 +32,26 @@ async function add(domainId, data, addTask = true) {
|
||||
coll.insertOne(data),
|
||||
]);
|
||||
if (addTask) {
|
||||
await task.add({
|
||||
type: 'judge',
|
||||
const t = {
|
||||
type: data.type || 'judge',
|
||||
event: data.type || 'judge',
|
||||
rid: res.insertedId,
|
||||
domainId,
|
||||
pid: data.pid,
|
||||
data: (pdoc || {}).data,
|
||||
lang: data.lang,
|
||||
code: data.code,
|
||||
});
|
||||
};
|
||||
if (t.type === 'judge') {
|
||||
t.data = pdoc.data;
|
||||
t.config = pdoc.config;
|
||||
} else {
|
||||
t.config = {
|
||||
time: data.time,
|
||||
memory: data.memory,
|
||||
input: data.input,
|
||||
};
|
||||
}
|
||||
await task.add(t);
|
||||
}
|
||||
return res.insertedId;
|
||||
}
|
||||
@@ -66,8 +78,7 @@ async function update(domainId, rid, $set, $push, $unset) {
|
||||
if ($set && Object.keys($set).length) upd.$set = $set;
|
||||
if ($push && Object.keys($push).length) upd.$push = $push;
|
||||
if ($unset && Object.keys($unset).length) upd.$unset = $unset;
|
||||
await coll.findOneAndUpdate({ domainId, _id }, upd);
|
||||
const rdoc = await coll.findOne({ _id });
|
||||
const rdoc = await coll.findOneAndUpdate({ domainId, _id }, upd, { returnOriginal: false });
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
return rdoc;
|
||||
}
|
||||
|
||||
+1
-10
@@ -1,4 +1,3 @@
|
||||
const cluster = require('cluster');
|
||||
const moment = require('moment-timezone');
|
||||
const db = require('../service/db');
|
||||
|
||||
@@ -8,7 +7,6 @@ async function add(task) {
|
||||
const t = { ...task };
|
||||
if (typeof t.executeAfter === 'object') t.executeAfter = t.executeAfter.getTime();
|
||||
t.count = t.count || 1;
|
||||
t.wait = t.wait || Object.keys(cluster.workers);
|
||||
t.executeAfter = t.executeAfter || new Date().getTime();
|
||||
const res = await coll.insertOne(t);
|
||||
return res.insertedId;
|
||||
@@ -29,16 +27,9 @@ function del(_id) {
|
||||
async function getFirst(query) {
|
||||
const q = { ...query };
|
||||
q.executeAfter = q.executeAfter || { $lt: new Date().getTime() };
|
||||
q.wait = { $elemMatch: { $eq: cluster.worker.id } };
|
||||
const res = await coll.find(q).sort('_id', 1).limit(1).toArray();
|
||||
if (res.length) {
|
||||
if (res[0].count === 1) await coll.deleteOne({ _id: res[0]._id });
|
||||
else {
|
||||
await coll.updateOne(
|
||||
{ _id: res[0]._id },
|
||||
{ $inc: { count: -1 }, $pull: { wait: cluster.worker.id } },
|
||||
);
|
||||
}
|
||||
await coll.deleteOne({ _id: res[0]._id });
|
||||
if (res[0].interval) {
|
||||
await coll.insertOne({
|
||||
...res[0], executeAfter: moment().add(...res[0].interval).toDate(),
|
||||
|
||||
@@ -132,6 +132,7 @@ async function changePassword(uid, currentPassword, newPassword) {
|
||||
|
||||
async function inc(_id, field, n = 1) {
|
||||
const udoc = await coll.findOne({ _id });
|
||||
if (!udoc) throw new UserNotFoundError(_id);
|
||||
udoc[field] = udoc[field] + n || n;
|
||||
await coll.updateOne({ _id }, { $set: { [field]: udoc[field] } });
|
||||
return udoc;
|
||||
|
||||
Reference in new issue
Block a user