mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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",
|
||||
"version": "2.23.13",
|
||||
"version": "2.23.14",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -33,8 +33,10 @@ async function _postJudge(rdoc: Rdoc) {
|
||||
: await problem.get(rdoc.domainId, rdoc.pid);
|
||||
const difficulty = difficultyAlgorithm(pdoc.nSubmit, pdoc.nAccept);
|
||||
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 problem.edit(pdoc.domainId, pdoc.docId, { difficulty });
|
||||
await Promise.all([
|
||||
record.update(rdoc.domainId, rdoc._id, { effective: true }),
|
||||
problem.edit(pdoc.domainId, pdoc.docId, { difficulty }),
|
||||
]);
|
||||
await bus.serial('record/judge', rdoc, updated);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class BlackListModel {
|
||||
@ArgMethod
|
||||
static async add(id: string, expire?: Date | number) {
|
||||
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();
|
||||
else if (expire instanceof Date) expireAt = expire;
|
||||
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,
|
||||
beginAt,
|
||||
expireAt,
|
||||
op: { $not: { $gte: maxOperations } },
|
||||
op: { $lt: maxOperations },
|
||||
}, { $inc: { op: 1 } }, { upsert: true });
|
||||
} catch (e) {
|
||||
throw new OpcountExceededError(op, periodSecs, maxOperations);
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
||||
FilterQuery,
|
||||
} from 'mongodb';
|
||||
import { Dictionary } from 'lodash';
|
||||
import { sum } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { STATUS } from './builtin';
|
||||
import task from './task';
|
||||
@@ -16,6 +16,13 @@ import db from '../service/db';
|
||||
class RecordModel {
|
||||
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> {
|
||||
const res = await RecordModel.coll.findOne({ _id });
|
||||
if (res && res.domainId === domainId) return res;
|
||||
@@ -86,7 +93,10 @@ class RecordModel {
|
||||
data.hidden = true;
|
||||
} else data.contest = contestOrConfig;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -151,7 +161,7 @@ class RecordModel {
|
||||
|
||||
static async getList(
|
||||
domainId: string, rids: ObjectID[], showHidden: boolean,
|
||||
): Promise<Dictionary<Rdoc>> {
|
||||
): Promise<Record<string, Rdoc>> {
|
||||
const r = {};
|
||||
rids = Array.from(new Set(rids));
|
||||
const rdocs = await RecordModel.coll.find({ domainId, _id: { $in: rids } }).toArray();
|
||||
|
||||
Reference in new issue
Block a user