From 29652ca8fb45a598dea12898e4e847c3e6800de9 Mon Sep 17 00:00:00 2001 From: sean Date: Thu, 12 Jun 2025 17:31:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=88=B7=E6=96=B0=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/core/pouch/commands/ActionCommand.js | 12 ++++-------- src/lib/core/pouch/commands/HelloCommand.js | 4 ++-- src/lib/core/resource/resourceManager.js | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/lib/core/pouch/commands/ActionCommand.js b/src/lib/core/pouch/commands/ActionCommand.js index 5e3e359..11e5896 100644 --- a/src/lib/core/pouch/commands/ActionCommand.js +++ b/src/lib/core/pouch/commands/ActionCommand.js @@ -83,14 +83,10 @@ ${COMMANDS.HELLO} async getRoleInfo (roleId) { logger.debug(`[ActionCommand] getRoleInfo调用,角色ID: ${roleId}`) - // 懒加载HelloCommand实例 - if (!this.helloCommand) { - logger.debug(`[ActionCommand] 创建新的HelloCommand实例`) - const HelloCommand = require('./HelloCommand') - this.helloCommand = new HelloCommand() - } else { - logger.debug(`[ActionCommand] 复用现有HelloCommand实例`) - } + // 总是创建新的HelloCommand实例,确保获取最新的角色信息 + logger.debug(`[ActionCommand] 创建新的HelloCommand实例以获取最新角色信息`) + const HelloCommand = require('./HelloCommand') + this.helloCommand = new HelloCommand() const result = await this.helloCommand.getRoleInfo(roleId) logger.debug(`[ActionCommand] HelloCommand.getRoleInfo返回:`, result) diff --git a/src/lib/core/pouch/commands/HelloCommand.js b/src/lib/core/pouch/commands/HelloCommand.js index 076010b..06cf96f 100644 --- a/src/lib/core/pouch/commands/HelloCommand.js +++ b/src/lib/core/pouch/commands/HelloCommand.js @@ -26,8 +26,8 @@ class HelloCommand extends BasePouchCommand { */ async loadRoleRegistry () { try { - // 使用新的ResourceManager架构初始化 - await this.resourceManager.initializeWithNewArchitecture() + // 强制刷新资源发现,确保能发现新创建的角色 + await this.resourceManager.forceRefresh() // 获取所有角色相关的资源 const roleRegistry = {} diff --git a/src/lib/core/resource/resourceManager.js b/src/lib/core/resource/resourceManager.js index b192f17..09a4d93 100644 --- a/src/lib/core/resource/resourceManager.js +++ b/src/lib/core/resource/resourceManager.js @@ -189,6 +189,26 @@ class ResourceManager { return await protocol.resolve(parsed.path, parsed.queryParams) } + /** + * 强制重新初始化资源发现(清除缓存) + * 用于解决新创建角色无法被发现的问题 + */ + async forceRefresh() { + // 1. 清除ResourceManager的初始化状态 + this.initialized = false + + // 2. 清空注册表 + this.registry.clear() + + // 3. 清除所有发现器的缓存 + if (this.discoveryManager && this.discoveryManager.clearCache) { + this.discoveryManager.clearCache() + } + + // 4. 重新初始化 + await this.initializeWithNewArchitecture() + } + /** * 获取所有已注册的协议 * @returns {Array} 协议名称列表