mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add judge priority system
This commit is contained in:
1 parent
c43663a1d1
commit
faae0805c1
5 files changed
+20
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.23.13",
|
"version": "2.23.14",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ async function _postJudge(rdoc: Rdoc) {
|
|||||||
: await problem.get(rdoc.domainId, rdoc.pid);
|
: await problem.get(rdoc.domainId, rdoc.pid);
|
||||||
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
||||||
if (!updated) await record.updateMulti(rdoc.domainId, { uid: rdoc.uid, status: builtin.STATUS.STATUS_ACCEPTED }, { effective: false });
|
if (!updated) await record.updateMulti(rdoc.domainId, { uid: rdoc.uid, status: builtin.STATUS.STATUS_ACCEPTED }, { effective: false });
|
||||||
await record.update(rdoc.domainId, rdoc._id, { effective: true });
|
await Promise.all([
|
||||||
await problem.edit(pdoc.domainId, pdoc.docId, { difficulty });
|
record.update(rdoc.domainId, rdoc._id, { effective: true }),
|
||||||
|
problem.edit(pdoc.domainId, pdoc.docId, { difficulty }),
|
||||||
|
]);
|
||||||
await bus.serial('record/judge', rdoc, updated);
|
await bus.serial('record/judge', rdoc, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class BlackListModel {
|
|||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async add(id: string, expire?: Date | number) {
|
static async add(id: string, expire?: Date | number) {
|
||||||
let expireAt;
|
let expireAt;
|
||||||
if (expire === 0) expireAt = moment().add(1000, 'years').toDate();
|
if (expire === 0) expireAt = moment().add(1000, 'months').toDate();
|
||||||
if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
|
if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
|
||||||
else if (expire instanceof Date) expireAt = expire;
|
else if (expire instanceof Date) expireAt = expire;
|
||||||
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
|
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export async function inc(op: string, ident: string, periodSecs: number, maxOper
|
|||||||
ident,
|
ident,
|
||||||
beginAt,
|
beginAt,
|
||||||
expireAt,
|
expireAt,
|
||||||
op: { $not: { $gte: maxOperations } },
|
op: { $lt: maxOperations },
|
||||||
}, { $inc: { op: 1 } }, { upsert: true });
|
}, { $inc: { op: 1 } }, { upsert: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new OpcountExceededError(op, periodSecs, maxOperations);
|
throw new OpcountExceededError(op, periodSecs, maxOperations);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
||||||
FilterQuery,
|
FilterQuery,
|
||||||
} from 'mongodb';
|
} from 'mongodb';
|
||||||
import { Dictionary } from 'lodash';
|
import { sum } from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { STATUS } from './builtin';
|
import { STATUS } from './builtin';
|
||||||
import task from './task';
|
import task from './task';
|
||||||
@@ -16,6 +16,13 @@ import db from '../service/db';
|
|||||||
class RecordModel {
|
class RecordModel {
|
||||||
static coll: Collection<Rdoc> = db.collection('record');
|
static coll: Collection<Rdoc> = db.collection('record');
|
||||||
|
|
||||||
|
static async submissionPriority(uid: number) {
|
||||||
|
const pending = await task.count({ uid });
|
||||||
|
const timeRecent = await RecordModel.coll
|
||||||
|
.find({ _id: { $gte: Time.getObjectID(moment().add(-1, 'hour')) }, uid }).project({ time: 1 }).toArray();
|
||||||
|
return -(pending * (sum(timeRecent) / 1000));
|
||||||
|
}
|
||||||
|
|
||||||
static async get(domainId: string, _id: ObjectID): Promise<Rdoc | null> {
|
static async get(domainId: string, _id: ObjectID): Promise<Rdoc | null> {
|
||||||
const res = await RecordModel.coll.findOne({ _id });
|
const res = await RecordModel.coll.findOne({ _id });
|
||||||
if (res && res.domainId === domainId) return res;
|
if (res && res.domainId === domainId) return res;
|
||||||
@@ -86,7 +93,10 @@ class RecordModel {
|
|||||||
data.hidden = true;
|
data.hidden = true;
|
||||||
} else data.contest = contestOrConfig;
|
} else data.contest = contestOrConfig;
|
||||||
const res = await RecordModel.coll.insertOne(data);
|
const res = await RecordModel.coll.insertOne(data);
|
||||||
if (addTask) await RecordModel.judge(domainId, res.insertedId);
|
if (addTask) {
|
||||||
|
const priority = await RecordModel.submissionPriority(uid);
|
||||||
|
await RecordModel.judge(domainId, res.insertedId, 1 - priority);
|
||||||
|
}
|
||||||
return res.insertedId;
|
return res.insertedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +161,7 @@ class RecordModel {
|
|||||||
|
|
||||||
static async getList(
|
static async getList(
|
||||||
domainId: string, rids: ObjectID[], showHidden: boolean,
|
domainId: string, rids: ObjectID[], showHidden: boolean,
|
||||||
): Promise<Dictionary<Rdoc>> {
|
): Promise<Record<string, Rdoc>> {
|
||||||
const r = {};
|
const r = {};
|
||||||
rids = Array.from(new Set(rids));
|
rids = Array.from(new Set(rids));
|
||||||
const rdocs = await RecordModel.coll.find({ domainId, _id: { $in: rids } }).toArray();
|
const rdocs = await RecordModel.coll.find({ domainId, _id: { $in: rids } }).toArray();
|
||||||
|
|||||||
Reference in new issue
Block a user