mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
更改updateStatus逻辑,导入problem.status
This commit is contained in:
1 parent
4c3284c917
commit
d04628148f
6 files changed
+71
-73
No files matched your search
@@ -1,5 +0,0 @@
|
||||
module.exports = function ignoreFailure(func, ...params) {
|
||||
try {
|
||||
func(...params);
|
||||
} catch (e) { } // eslint-disable-line no-empty
|
||||
};
|
||||
@@ -19,16 +19,14 @@ async function _postJudge(rdoc) {
|
||||
contest.updateStatus(rdoc.tid, rdoc.uid, rdoc._id, rdoc.pid, accept, rdoc.score),
|
||||
);
|
||||
}
|
||||
if (!rdoc.rejudged) {
|
||||
if (await problem.updateStatus(rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) {
|
||||
if (accept) {
|
||||
if (accept && !rdoc.rejudged) {
|
||||
tasks.push(
|
||||
problem.inc(rdoc.pid, 'nAccept', 1),
|
||||
user.inc(rdoc.uid, 'nAccept', 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -19,20 +19,22 @@ exports.udoc = {
|
||||
loginat: new Date(),
|
||||
loginip: '0.0.0.0',
|
||||
};
|
||||
|
||||
exports.pdoc = {
|
||||
_id: new ObjectID(),
|
||||
pid: 'P1000',
|
||||
owner: 0,
|
||||
title: 'No Title',
|
||||
content: 'No Content',
|
||||
nSubmit: 0,
|
||||
nAccept: 0,
|
||||
tag: [],
|
||||
category: [],
|
||||
data: null,
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
/*
|
||||
export interface Pdoc {
|
||||
_id: ObjectID
|
||||
pid: string
|
||||
owner: number
|
||||
title: string
|
||||
content: string
|
||||
nSubmit: number
|
||||
nAccept: number
|
||||
tag: string[]
|
||||
category: string[],
|
||||
data: ObjectID | null
|
||||
hidden: boolean
|
||||
}
|
||||
export interface TestCase {
|
||||
time: number,
|
||||
memory: number,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const gridfs = require('../service/gridfs');
|
||||
const { STATUS_ACCEPTED } = require('./builtin').STATUS;
|
||||
const { ProblemNotFoundError } = require('../error');
|
||||
const validator = require('../lib/validator');
|
||||
const db = require('../service/db.js');
|
||||
const gridfs = require('../service/gridfs');
|
||||
|
||||
const coll = db.collection('problem');
|
||||
const collStatus = db.collection('problem.status');
|
||||
@@ -141,12 +142,16 @@ async function getListStatus(uid, pids) {
|
||||
return r;
|
||||
}
|
||||
async function updateStatus(pid, uid, rid, status) {
|
||||
const res = await collStatus.findOneAndUpdate(
|
||||
const cur = collStatus.findOne({ pid, uid });
|
||||
if (cur && status !== STATUS_ACCEPTED) {
|
||||
if (cur.status !== STATUS_ACCEPTED) return false;
|
||||
}
|
||||
await collStatus.updateOne(
|
||||
{ pid, uid },
|
||||
{ $set: { rid, status } },
|
||||
{ upsert: true },
|
||||
);
|
||||
return res.value;
|
||||
return true;
|
||||
}
|
||||
async function setTestdata(_id, readStream) {
|
||||
const pdoc = await getById(_id);
|
||||
|
||||
@@ -4,26 +4,22 @@ const { ObjectID } = global.Hydro.nodeModules.bson;
|
||||
const dst = global.Hydro.service.db;
|
||||
const { problem } = global.Hydro.model.problem;
|
||||
|
||||
function parseSolution(doc) {
|
||||
return {
|
||||
_id: doc._id,
|
||||
title: doc.title,
|
||||
content: doc.content,
|
||||
vote: doc.vote,
|
||||
};
|
||||
}
|
||||
const RULES = ['', 'oi', 'acm'];
|
||||
|
||||
const tasks = {
|
||||
async problem(src, report) {
|
||||
let count = await src.collection('document').find({ doc_type: 10 }).count();
|
||||
await report({ progress: 1, message: `Found ${count} problems.` });
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document').find({ doc_type: 10 })
|
||||
.skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
const problems = [];
|
||||
for (const doc of docs) {
|
||||
problems.push({
|
||||
user: async (docs) => docs.map((doc) => ({
|
||||
_id: doc._id,
|
||||
uname: doc.uname,
|
||||
unameLower: doc.uname_lower,
|
||||
salt: doc.salt,
|
||||
hash: doc.hash.split('|')[1],
|
||||
hashType: doc.hash.split('|')[0] === 'vj4' ? 'hydro' : doc.hash.split('|')[0],
|
||||
gravatar: doc.gravatar,
|
||||
email: doc.mail,
|
||||
emailLower: doc.mail_lower,
|
||||
|
||||
})),
|
||||
problem: async (docs) => docs.map((doc) => ({
|
||||
_id: doc._id,
|
||||
pid: doc.doc_id || new ObjectID(),
|
||||
title: doc.title,
|
||||
@@ -34,15 +30,8 @@ const tasks = {
|
||||
tag: doc.tag,
|
||||
nSubmit: doc.num_submit,
|
||||
nAccept: doc.num_accept,
|
||||
});
|
||||
}
|
||||
await dst.collection('problem').insertMany(problems);
|
||||
}
|
||||
count = await src.collection('document.status').find({ doc_type: 10 }).count();
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document.status').find({ doc_type: 10 })
|
||||
.skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
})),
|
||||
'problem.status': async (docs) => {
|
||||
const problems = [];
|
||||
for (const doc of docs) {
|
||||
problems.push({
|
||||
@@ -52,21 +41,9 @@ const tasks = {
|
||||
status: doc.status,
|
||||
});
|
||||
}
|
||||
await dst.collection('problem.status').insertMany(problems);
|
||||
}
|
||||
await report({ progress: 1, message: `Found ${count} problems.` });
|
||||
return problems;
|
||||
},
|
||||
async contest(src, report) {
|
||||
const RULES = ['', 'oi', 'acm'];
|
||||
const count = await src.collection('document').find({ doc_type: 30 }).count();
|
||||
await report({ progress: 1, message: `Found ${count} contests.` });
|
||||
for (let i = 0; i <= Math.floor(count / 50); i++) {
|
||||
const docs = await src.collection('document').find({ doc_type: 30 })
|
||||
.skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
const contests = [];
|
||||
for (const doc of docs) {
|
||||
contests.push({
|
||||
contest: async (docs) => docs.map((doc) => ({
|
||||
_id: doc._id,
|
||||
title: doc.title,
|
||||
content: doc.content,
|
||||
@@ -76,13 +53,33 @@ const tasks = {
|
||||
endAt: doc.end_at,
|
||||
pids: doc.pids,
|
||||
attend: doc.attend,
|
||||
});
|
||||
}
|
||||
await dst.collection('contest').insertMany(contests);
|
||||
}
|
||||
},
|
||||
})),
|
||||
solution: async (docs) => docs.map((doc) => ({
|
||||
_id: doc._id,
|
||||
title: doc.title,
|
||||
content: doc.content,
|
||||
vote: doc.vote,
|
||||
})),
|
||||
};
|
||||
|
||||
const cursor = {
|
||||
problem: (s) => s.collection('document').find({ doc_type: 10 }),
|
||||
'problem.status': (s) => s.collection('document.status').find({ doc_type: 10 }),
|
||||
contest: (s) => s.collection('document').find({ doc_type: 30 }),
|
||||
user: (s) => s.collection('user').find(),
|
||||
};
|
||||
|
||||
async function task(name, src, report) {
|
||||
const count = await cursor[name](src).count();
|
||||
await report({ progress: 1, message: `${name}: ${count}` });
|
||||
const total = Math.floor(count / 50);
|
||||
for (let i = 0; i <= total; i++) {
|
||||
const docs = await cursor[name](src).skip(i * 50).limit(50).toArray();
|
||||
await dst.collection(name).insertMany(await tasks[name](docs));
|
||||
await report({ progress: Math.round(100 * (i / total)) });
|
||||
}
|
||||
}
|
||||
|
||||
async function migrateVijos({
|
||||
host, port, name, username, password,
|
||||
}, report = () => { }) {
|
||||
@@ -99,8 +96,9 @@ async function migrateVijos({
|
||||
value: (await src.collection('system').findOne({ _id: 'user_counter' })).value,
|
||||
});
|
||||
await report({ progress: 1, message: 'Collection:system done.' });
|
||||
await tasks.problem(src, report);
|
||||
await tasks.contest(src, report);
|
||||
await task('problem', src, report);
|
||||
await task('problem.status', src, report);
|
||||
await task('contest', src, report);
|
||||
}
|
||||
|
||||
global.Hydro.script.migrateVijos = module.exports = migrateVijos;
|
||||
@@ -5,7 +5,7 @@ import * as recordEnum from 'vj/constant/record';
|
||||
const page = new NamedPage('judge_playground', async () => {
|
||||
const { default: SockJs } = await import('sockjs-client');
|
||||
|
||||
const sock = new SockJs(`/judge/consume-conn?token=${ UIContext.csrfToken }`);
|
||||
const sock = new SockJs(`/judge/consume-conn?token=${UiContext.csrfToken}`);
|
||||
sock.onopen = () => {
|
||||
const div = $('<div class="section visible">').appendTo('#messages');
|
||||
$('<div class="section__header"><h1 class="section__title">Connection opened.</h1></div>')
|
||||
|
||||
Reference in new issue
Block a user