This commit is contained in:
undefined committed 2020-06-26 16:34:37 +08:00
1 parent 560e920624
commit d59710ddf1
13 files changed
+181 -49

No files matched your search

+6 -2
View File
@@ -92,7 +92,10 @@ class DiscussionNodeHandler extends DiscussionHandler {
page,
await system.get('DISCUSSION_PER_PAGE'),
);
const udict = await user.getList(domainId, ddocs.map((ddoc) => ddoc.owner));
const [udict, vnodes] = await Promise.all([
user.getList(domainId, ddocs.map((ddoc) => ddoc.owner)),
discussion.getNodes(domainId),
]);
const path = [
['Hydro', 'homepage'],
['discussion_main', 'discussion_main'],
@@ -109,6 +112,7 @@ class DiscussionNodeHandler extends DiscussionHandler {
vndict,
vnode: this.vnode,
page_name: 'discussion_node',
vnodes,
};
}
}
@@ -141,7 +145,7 @@ class DiscussionCreateHandler extends DiscussionHandler {
title, content, this.request.ip, highlight,
);
this.response.body = { did };
this.response.redirect = `/discuss/${did}`;
this.response.redirect = this.url('discussion_detail', { did });
}
}
+1 -1
View File
@@ -151,7 +151,7 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
async onRecordChange(data) {
const rdoc = data.value;
if (rdoc._id.toString() !== this.rid.toString()) return;
if (!rdoc._id.equals(this.rid)) return;
this.send({
status_html: await this.renderHTML('record_detail_status.html', { rdoc }),
summary_html: await this.renderHTML('record_detail_summary.html', { rdoc }),
+11 -1
View File
@@ -5,7 +5,17 @@ function warp(func, type) {
const time = new Date();
func(...args);
if (global.Hydro.model.message) {
global.Hydro.model.message.send(1, 1, yaml.safeDump({ time, type, args }));
try {
for (let i = 0; i <= args.length; i++) {
if (args[i] instanceof Error) {
// js-yaml cannot dump [object Error]
args[i] = `${args[i].message}\n${args[i].stack}`;
}
}
global.Hydro.model.message.send(1, 1, yaml.dump({ time, type, args }, {}));
} catch (e) {
func(e.message);
}
}
};
}
+1
View File
@@ -24,6 +24,7 @@ function add(domainId, parentType, parentId, owner, title, content, ip = null, h
highlight,
nReply: 0,
updateAt: new Date(),
views: 0,
},
);
}
+7 -5
View File
@@ -98,11 +98,12 @@ async function getList(domainId, rids, showHidden = false) {
return r;
}
function getUserInProblemMulti(domainId, uid, pid, getHidden = false) {
if (getHidden) return coll.find({ domainId, owner: uid, pid });
return coll.find({
domainId, owner: uid, pid, hidden: false,
});
function getUserInProblemMulti(domainId, uid, pid) {
return coll.find({ domainId, uid, pid });
}
function getByUid(domainId, uid) {
return coll.find({ domainId, uid }).toArray();
}
async function judge(domainId, rid) {
@@ -144,6 +145,7 @@ global.Hydro.model.record = module.exports = {
reset,
getList,
getUserInProblemMulti,
getByUid,
judge,
rejudge,
};
+19 -6
View File
@@ -4,8 +4,10 @@ const db = require('../service/db');
const coll = db.collection('task');
async function add(task) {
task.executeAfter = task.executeAfter || new Date();
const res = await coll.insertOne(task);
const t = { ...task };
if (typeof t.executeAfter === 'object') t.executeAfter = t.executeAfter.getTime();
t.executeAfter = t.executeAfter || new Date().getTime();
const res = await coll.insertOne(t);
return res.insertedId;
}
@@ -22,8 +24,9 @@ function del(_id) {
}
async function getFirst(query) {
query.executeAfter = query.executeAfter || { $lte: new Date() };
const res = await coll.find(query).sort('_id', 1).limit(1).toArray();
const q = { ...query };
q.executeAfter = q.executeAfter || { $lt: new Date().getTime() };
const res = await coll.find(q).sort('_id', 1).limit(1).toArray();
if (res.length) {
await coll.deleteOne({ _id: res[0]._id });
if (res[0].interval) {
@@ -37,9 +40,19 @@ async function getFirst(query) {
}
async function consume(query, cb) {
setInterval(async () => {
let isRunning = false;
const interval = setInterval(async () => {
if (isRunning) return;
isRunning = true;
const res = await getFirst(query);
if (res) cb(res);
if (res) {
try {
await cb(res);
} catch (e) {
clearInterval(interval);
}
}
isRunning = false;
}, 100);
}
+3 -2
View File
@@ -175,8 +175,8 @@ class Handler {
this.response.type = 'text/html';
}
renderTitle(str) { // eslint-disable-line class-methods-use-this
return str;
renderTitle(str) {
return `${this.translate(str)} - Hydro`;
}
checkPerm(...args) {
@@ -261,6 +261,7 @@ class Handler {
path: this.request.path,
uid: this.session.uid,
});
this.UIContext.csrfToken = this.csrfToken;
this.preferJson = (this.request.headers.accept || '').includes('application/json');
}