mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
markdown语法增强,错误修复
This commit is contained in:
1 parent
4b3c10b4eb
commit
a29b801e72
22 files changed
+311
-200
No files matched your search
@@ -348,7 +348,8 @@ const ContestHandlerMixin = (c) => class extends c {
|
||||
}
|
||||
|
||||
async verifyProblems(domainId, pids) { // eslint-disable-line class-methods-use-this
|
||||
return await problem.getList(domainId, pids, true);
|
||||
await problem.getList(domainId, pids, true);
|
||||
return pids;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,4 +25,8 @@ async function inc(op, ident, periodSecs, maxOperations) {
|
||||
}
|
||||
}
|
||||
|
||||
global.Hydro.model.opcount = module.exports = { inc };
|
||||
function ensureIndexes() {
|
||||
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||||
}
|
||||
|
||||
global.Hydro.model.opcount = module.exports = { inc, ensureIndexes };
|
||||
@@ -44,13 +44,16 @@ async function add(domainId, title, content, owner, {
|
||||
* @param {string} domainId
|
||||
* @param {string|number} pid
|
||||
* @param {number} uid
|
||||
* @returns {Pdoc}
|
||||
* @returns {Promise<Pdoc>}
|
||||
*/
|
||||
async function get(domainId, pid, uid = null) {
|
||||
async function get(domainId, pid, uid = null, doThrow = true) {
|
||||
const pdoc = Number.isInteger(pid)
|
||||
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
||||
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
|
||||
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||
if (!pdoc) {
|
||||
if (doThrow) throw new ProblemNotFoundError(domainId, pid);
|
||||
return null;
|
||||
}
|
||||
if (uid) {
|
||||
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
|
||||
}
|
||||
@@ -63,7 +66,7 @@ async function get(domainId, pid, uid = null) {
|
||||
* @param {object} sort
|
||||
* @param {number} page
|
||||
* @param {number} limit
|
||||
* @returns {Pdoc[]}
|
||||
* @returns {Promise<Pdoc[]>}
|
||||
*/
|
||||
function getMany(domainId, query, sort, page, limit) {
|
||||
return document.getMulti(domainId, query).sort(sort).skip((page - 1) * limit).limit(limit)
|
||||
@@ -116,7 +119,7 @@ async function random(domainId, query) {
|
||||
}
|
||||
|
||||
async function getList(domainId, pids, doThrow = true) {
|
||||
pids = new Set(pids);
|
||||
pids = Array.from(new Set(pids));
|
||||
const r = {};
|
||||
const pdocs = await document.getMulti(
|
||||
domainId, document.TYPE_PROBLEM,
|
||||
@@ -125,7 +128,7 @@ async function getList(domainId, pids, doThrow = true) {
|
||||
for (const pdoc of pdocs) {
|
||||
r[pdoc.docId] = r[pdoc.pid] = pdoc;
|
||||
}
|
||||
if (pdocs.length !== pids.size) {
|
||||
if (pdocs.length !== pids.length) {
|
||||
if (doThrow) {
|
||||
for (const pid of pids) {
|
||||
if (!r[pid]) throw new ProblemNotFoundError(domainId, pid);
|
||||
|
||||
+18
-16
@@ -12,7 +12,7 @@ const coll = db.collection('record');
|
||||
* @param {string} domainId
|
||||
* @param {import('../interface').Record} data
|
||||
*/
|
||||
async function add(domainId, data) {
|
||||
async function add(domainId, data, addTask = true) {
|
||||
_.defaults(data, {
|
||||
status: STATUS_WAITING,
|
||||
domainId,
|
||||
@@ -27,18 +27,20 @@ async function add(domainId, data) {
|
||||
judgeAt: null,
|
||||
});
|
||||
const [pdoc, res] = await Promise.all([
|
||||
problem.get(domainId, data.pid),
|
||||
problem.get(domainId, data.pid, null, false),
|
||||
coll.insertOne(data),
|
||||
]);
|
||||
await task.add({
|
||||
type: 'judge',
|
||||
rid: res.insertedId,
|
||||
domainId,
|
||||
pid: data.pid,
|
||||
data: pdoc.data,
|
||||
lang: data.lang,
|
||||
code: data.code,
|
||||
});
|
||||
if (addTask) {
|
||||
await task.add({
|
||||
type: 'judge',
|
||||
rid: res.insertedId,
|
||||
domainId,
|
||||
pid: data.pid,
|
||||
data: (pdoc || {}).data,
|
||||
lang: data.lang,
|
||||
code: data.code,
|
||||
});
|
||||
}
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
@@ -54,16 +56,16 @@ async function get(domainId, rid) {
|
||||
return rdoc;
|
||||
}
|
||||
|
||||
function getMany(domainId, query, sort, page, limit) {
|
||||
return coll.find({ ...query, domainId }).sort(sort).skip((page - 1) * limit).limit(limit)
|
||||
.toArray();
|
||||
function getMulti(domainId, query) {
|
||||
return coll.find({ ...query, domainId });
|
||||
}
|
||||
|
||||
async function update(domainId, rid, $set, $push) {
|
||||
async function update(domainId, rid, $set, $push, $unset) {
|
||||
const _id = new ObjectID(rid);
|
||||
const upd = {};
|
||||
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 });
|
||||
if (!rdoc) throw new RecordNotFoundError(rid);
|
||||
@@ -136,7 +138,7 @@ async function rejudge(domainId, rid) {
|
||||
global.Hydro.model.record = module.exports = {
|
||||
add,
|
||||
get,
|
||||
getMany,
|
||||
getMulti,
|
||||
update,
|
||||
count,
|
||||
reset,
|
||||
|
||||
Reference in new issue
Block a user