From 6d639f76f276a805a5d27d0e2c8abf35e1adbf8a Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 19 Feb 2026 14:29:05 +0800 Subject: [PATCH] core: fix #1133 --- packages/hydrooj/src/loader.ts | 13 ++++++++++--- packages/hydrooj/src/settings.ts | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/hydrooj/src/loader.ts b/packages/hydrooj/src/loader.ts index 2a4071ab9..4f9c1735b 100644 --- a/packages/hydrooj/src/loader.ts +++ b/packages/hydrooj/src/loader.ts @@ -48,6 +48,7 @@ export class Loader extends Service { public state: Record = Object.create(null); public suspend = false; public cache: Record = Object.create(null); + private schemaCache = new WeakMap, Record>>(); // public warnings: Record = Object.create(null); static inject = ['setting', 'timer', 'i18n', 'logger']; @@ -94,12 +95,18 @@ export class Loader extends Service { } } + buildSchema(schema: Schema, scope?: string) { + if (!scope) return schema; + const cache = this.schemaCache.get(schema) || {}; + cache[scope] ||= Schema.object({ [scope]: schema }); + this.schemaCache.set(schema, cache); + return cache[scope]; + } + async resolveConfig(plugin: any, configScope: string, dynamic = true) { const schema = plugin['Config'] || plugin['schema']; if (!schema) return Object.freeze({}); - const schemaRequest = configScope ? Schema.object({ - [configScope]: schema, - }) : schema; + const schemaRequest = this.buildSchema(schema, configScope); await this.ctx.setting._tryMigrateConfig(schemaRequest); const res = this.ctx.setting.requestConfig(schemaRequest, dynamic); return configScope ? res[configScope] : res; diff --git a/packages/hydrooj/src/settings.ts b/packages/hydrooj/src/settings.ts index e89e5a49a..b26b3d797 100644 --- a/packages/hydrooj/src/settings.ts +++ b/packages/hydrooj/src/settings.ts @@ -150,16 +150,18 @@ export class SettingService extends Service { } requestConfig(s: Schema, dynamic = true): S { - this.ctx.effect(() => { - logger.debug('Loading config', s); - this.settings.push(s); - this._applySchema(); - return () => { - logger.debug('Unloading config', s); - this.settings = this.settings.filter((v) => v !== s); + if (!this.settings.includes(s)) { + this.ctx.effect(() => { + logger.debug('Loading config', s); + this.settings.push(s); this._applySchema(); - }; - }); + return () => { + logger.debug('Unloading config', s); + this.settings = this.settings.filter((v) => v !== s); + this._applySchema(); + }; + }); + } let curValue = s(this.systemConfig); if (!dynamic) return curValue; this.ctx.on('system/setting', () => {