From c63d7c16c1634a005a124ee189136e66cf0d1403 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 6 Oct 2022 03:39:38 +0800 Subject: [PATCH] core: fix load priority --- packages/hydrooj/src/entry/worker.ts | 5 +++-- packages/hydrooj/src/model/setting.ts | 24 +++++++++++------------- packages/hydrooj/src/script/rating.ts | 2 +- packages/hydrooj/src/upgrade.ts | 2 +- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/hydrooj/src/entry/worker.ts b/packages/hydrooj/src/entry/worker.ts index 0bc2d8f98..d3f7d35eb 100644 --- a/packages/hydrooj/src/entry/worker.ts +++ b/packages/hydrooj/src/entry/worker.ts @@ -44,14 +44,15 @@ export async function apply(ctx: Context) { await ctx.root.start(); require('../lib/index'); await lib(pending, fail, ctx); + await ctx.lifecycle.flush(); + + await setting(pending, fail, require('../model/setting')); ctx.plugin(require('../service/monitor')); await service(pending, fail, ctx); await builtinModel(ctx); await model(pending, fail, ctx); await ctx.lifecycle.flush(); - const modelSetting = require('../model/setting'); - await setting(pending, fail, modelSetting); const handlerDir = path.resolve(__dirname, '..', 'handler'); const handlers = await fs.readdir(handlerDir); for (const h of handlers) { diff --git a/packages/hydrooj/src/model/setting.ts b/packages/hydrooj/src/model/setting.ts index 8a1e6782c..97f18892e 100644 --- a/packages/hydrooj/src/model/setting.ts +++ b/packages/hydrooj/src/model/setting.ts @@ -241,14 +241,13 @@ SystemSetting( export const langs: Record = {}; export async function apply(ctx: Context) { - logger.debug('Ensuring settings'); + logger.info('Ensuring settings'); const system = global.Hydro.model.system; for (const setting of SYSTEM_SETTINGS) { - if (setting.value) { - const current = await global.Hydro.service.db.collection('system').findOne({ _id: setting.key }); - if (!current || current.value == null || current.value === '') { - await retry(system.set, setting.key, setting.value); - } + if (!setting.value) continue; + const current = await global.Hydro.service.db.collection('system').findOne({ _id: setting.key }); + if (!current || current.value == null || current.value === '') { + await retry(system.set, setting.key, setting.value); } } try { @@ -259,13 +258,12 @@ export async function apply(ctx: Context) { ServerLangSettingNode.range = range; } catch (e) { /* Ignore */ } ctx.on('system/setting', (args) => { - if (args.hydrooj?.langs) { - Object.assign(langs, parseLang(args.hydrooj.langs)); - const range = {}; - for (const key in langs) range[key] = langs[key].display; - LangSettingNode.range = range; - ServerLangSettingNode.range = range; - } + if (!args.hydrooj?.langs) return; + Object.assign(langs, parseLang(args.hydrooj.langs)); + const range = {}; + for (const key in langs) range[key] = langs[key].display; + LangSettingNode.range = range; + ServerLangSettingNode.range = range; }); } diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index 628b29e70..a39b41ab5 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -64,7 +64,7 @@ export const RpTypes: Record = { journal: { $ne: null }, }).sort(contest.RULES[tdoc.rule].statusSort); if (!await cursor.count()) continue; - const [rankedTsdocs] = await contest.RULES[tdoc.rule].ranked(tdoc, cursor); + const rankedTsdocs = await contest.RULES[tdoc.rule].ranked(tdoc, cursor); const users = rankedTsdocs.map((i) => ({ uid: i[1].uid, rank: i[0], old: udict[i[1].uid] })); // FIXME sum(rating.new) always less than sum(rating.old) for (const udoc of rating(users)) udict[udoc.uid] = udoc.new; diff --git a/packages/hydrooj/src/upgrade.ts b/packages/hydrooj/src/upgrade.ts index bf6e02d2f..d30b1fcaf 100644 --- a/packages/hydrooj/src/upgrade.ts +++ b/packages/hydrooj/src/upgrade.ts @@ -401,7 +401,7 @@ const scripts: UpgradeScript[] = [ return true; }, async function _59_60() { - const langs = await system.get('hydrooj.langs'); + const langs = system.get('hydrooj.langs'); await system.set('hydrooj.langs', langs.replace(/\$\{dir\}/g, '/w').replace(/\$\{name\}/g, 'foo')); return true; },