core: update hook usage

This commit is contained in:
undefined committed 2022-09-23 20:10:36 +08:00
1 parent ab933bc9d5
commit 757b5e6bc1
27 files changed
+63 -64

No files matched your search

+5 -5
View File
@@ -1,6 +1,8 @@
import { makeExecutableSchema } from '@graphql-tools/schema';
import { graphql, GraphQLSchema } from 'graphql';
import { resolvers, typeDefs } from 'graphql-scalars';
import { debounce } from 'lodash';
import { Context as PluginContext } from '../context';
import * as bus from '../service/bus';
import { Handler } from '../service/server';
@@ -90,10 +92,6 @@ export function rebuild() {
console.error(e);
}
}
bus.on('app/started', () => {
rebuild();
bus.on('api/update', rebuild);
});
class ApiHandler extends Handler {
query(q: string, variables: any) {
@@ -124,6 +122,8 @@ class ApiHandler extends Handler {
}
export const sideEffect = true;
export function apply(ctx) {
export function apply(ctx: PluginContext) {
ctx.Route('api', '/api', ApiHandler);
ctx.on('ready', rebuild);
ctx.on('api/update', debounce(rebuild));
}
+1 -1
View File
@@ -112,7 +112,7 @@ export async function postJudge(rdoc: RecordDoc) {
}
}
}
await bus.serial('record/judge', rdoc, updated);
await bus.parallel('record/judge', rdoc, updated);
}
export async function end(body: Partial<JudgeResultBody>) {
+4 -4
View File
@@ -171,7 +171,7 @@ export class ProblemMainHandler extends Handler {
});
sort = result.hits;
}
await bus.serial('problem/list', query, this);
await bus.parallel('problem/list', query, this);
// eslint-disable-next-line prefer-const
let [pdocs, ppcount, pcount] = fail
? [[], 0, 0]
@@ -304,7 +304,7 @@ export class ProblemRandomHandler extends Handler {
.map((i) => i.split('category:')[1]?.split(',')));
const q = buildQuery(this.user);
if (category.length) q.$and = category.map((tag) => ({ tag }));
await bus.serial('problem/list', q, this);
await bus.parallel('problem/list', q, this);
const pid = await problem.random(domainId, q);
if (!pid) throw new NoProblemError();
this.response.body = { pid };
@@ -360,7 +360,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
if (this.domain.langs) t.push(this.domain.langs.split(',').map((i) => i.trim()).filter((i) => i));
this.pdoc.config.langs = intersection(baseLangs, ...t);
}
await bus.serial('problem/get', this.pdoc, this);
await bus.parallel('problem/get', this.pdoc, this);
[this.psdoc, this.udoc] = await Promise.all([
problem.getStatus(domainId, this.pdoc.docId, this.user._id),
user.getById(domainId, this.pdoc.owner),
@@ -846,7 +846,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
this.response.body = {
psdocs, page, pcount, pscount, udict, pssdict, pdoc: this.pdoc, sid,
};
await bus.serial('handler/solution/get', this);
await bus.parallel('handler/solution/get', this);
}
@param('content', Types.Content)
+1 -1
View File
@@ -70,7 +70,7 @@ class StatusUpdateHandler extends Handler {
}
}
bus.once('app/started', () => coll.createIndex('updateAt', { expireAfterSeconds: 24 * 3600 }));
bus.on('app/started', () => coll.createIndex('updateAt', { expireAfterSeconds: 24 * 3600 }));
export async function apply(ctx) {
ctx.Route('status', '/status', StatusHandler);
+2 -2
View File
@@ -56,7 +56,7 @@ class TrainingMainHandler extends Handler {
@param('page', Types.PositiveInt, true)
async get(domainId: string, page = 1) {
const query: FilterQuery<TrainingDoc> = {};
await bus.serial('training/list', query, this);
await bus.parallel('training/list', query, this);
const [tdocs, tpcount] = await paginate(
training.getMulti(domainId),
page,
@@ -93,7 +93,7 @@ class TrainingDetailHandler extends Handler {
@param('tid', Types.ObjectID)
async get(domainId: string, tid: ObjectID) {
const tdoc = await training.get(domainId, tid);
await bus.serial('training/get', tdoc, this);
await bus.parallel('training/get', tdoc, this);
const pids = training.getPids(tdoc.dag);
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
const [owner, pdict] = await Promise.all([