mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: database structure update
This commit is contained in:
1 parent
dca8e28361
commit
4daf8bac80
24 files changed
+182
-263
No files matched your search
@@ -1,4 +1,6 @@
|
||||
/* eslint-disable no-constant-condition */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { STATUS } from '../model/builtin';
|
||||
import * as document from '../model/document';
|
||||
import db from '../service/db';
|
||||
@@ -6,11 +8,12 @@ import db from '../service/db';
|
||||
export const description = 'Recalculates nSubmit and nAccept in problem status.';
|
||||
|
||||
const sumStatus = (status) => ({ $sum: { $cond: [{ $eq: ['$status', status] }, 1, 0] } });
|
||||
const $match = { contest: { $ne: new ObjectID('000000000000000000000000') } };
|
||||
|
||||
export async function udoc(report) {
|
||||
report({ message: 'Udoc' });
|
||||
const pipeline = [
|
||||
{ $match: { hidden: false, type: { $ne: 'run' } } },
|
||||
{ $match },
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
@@ -28,8 +31,9 @@ export async function udoc(report) {
|
||||
];
|
||||
let bulk = db.collection('domain.user').initializeUnorderedBulkOp();
|
||||
const cursor = db.collection('record').aggregate(pipeline, { allowDiskUse: true });
|
||||
while (await cursor.hasNext()) {
|
||||
while (true) {
|
||||
const adoc = await cursor.next() as any;
|
||||
if (!adoc) break;
|
||||
bulk.find({
|
||||
domainId: adoc._id.domainId,
|
||||
uid: adoc._id.uid,
|
||||
@@ -50,7 +54,7 @@ export async function udoc(report) {
|
||||
export async function psdoc(report) {
|
||||
report({ message: 'Psdoc' });
|
||||
const pipeline = [
|
||||
{ $match: { hidden: false, type: { $ne: 'run' } } },
|
||||
{ $match },
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
@@ -59,8 +63,9 @@ export async function psdoc(report) {
|
||||
},
|
||||
];
|
||||
const data = db.collection('record').aggregate(pipeline, { allowDiskUse: true });
|
||||
while (await data.hasNext()) {
|
||||
while (true) {
|
||||
const adoc = await data.next() as any;
|
||||
if (!adoc) break;
|
||||
await document.setStatus(adoc._id.domainId, document.TYPE_PROBLEM, adoc._id.pid, adoc._id.uid, { nSubmit: adoc.nSubmit });
|
||||
}
|
||||
}
|
||||
@@ -68,7 +73,7 @@ export async function psdoc(report) {
|
||||
export async function pdoc(report) {
|
||||
report({ message: 'Pdoc' });
|
||||
const pipeline = [
|
||||
{ $match: { hidden: false, type: { $ne: 'run' } } },
|
||||
{ $match },
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
@@ -106,8 +111,9 @@ export async function pdoc(report) {
|
||||
let bulk = db.collection('document').initializeUnorderedBulkOp();
|
||||
const data = db.collection('record').aggregate(pipeline, { allowDiskUse: true });
|
||||
let cnt = 0;
|
||||
while (await data.hasNext()) {
|
||||
while (true) {
|
||||
const adoc = await data.next() as any;
|
||||
if (!adoc) break;
|
||||
const $set = {
|
||||
nSubmit: adoc.nSubmit,
|
||||
nAccept: adoc.nAccept,
|
||||
|
||||
@@ -32,7 +32,7 @@ async function runProblem(...arg: any[]) {
|
||||
const psdocs = await problem.getMultiStatus(
|
||||
pdoc.domainId, { docId: pdoc.docId, rid: { $ne: null } },
|
||||
).limit(100).skip((page - 1) * 100).project({ rid: 1, uid: 1 }).toArray();
|
||||
const rdict = await record.getList(pdoc.domainId, psdocs.map((psdoc) => psdoc.rid), true);
|
||||
const rdict = await record.getList(pdoc.domainId, psdocs.map((psdoc) => psdoc.rid));
|
||||
for (const psdoc of psdocs) {
|
||||
if (rdict[psdoc.rid.toHexString()]) {
|
||||
const rp = rdict[psdoc.rid.toHexString()].score * p;
|
||||
@@ -48,12 +48,12 @@ async function runContest(
|
||||
): Promise<void>;
|
||||
async function runContest(...arg: any[]) {
|
||||
const start = new Date().getTime();
|
||||
const tdoc: Tdoc<30 | 60> = (typeof arg[0] === 'string')
|
||||
? await contest.get(arg[0], arg[1], -1)
|
||||
const tdoc: Tdoc<30> = (typeof arg[0] === 'string')
|
||||
? await contest.get(arg[0], arg[1])
|
||||
: arg[0];
|
||||
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
||||
const report = (typeof arg[0] === 'string') ? arg[3] : arg[2];
|
||||
const cursor = contest.getMultiStatus(tdoc.domainId, tdoc.docId, tdoc.docType)
|
||||
const cursor = contest.getMultiStatus(tdoc.domainId, tdoc.docId)
|
||||
.sort(contest.RULES[tdoc.rule].statusSort);
|
||||
if (!await cursor.count()) return;
|
||||
const rankedTsdocs = await contest.RULES[tdoc.rule].ranked(tdoc, cursor);
|
||||
|
||||
Reference in new issue
Block a user