From b589307ebb1b304f8231550e5d7531bd5906f2c5 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 29 Jun 2026 13:38:05 +0000 Subject: [PATCH] =?UTF-8?q?perf(apps):=20=E8=A7=92=E6=A0=87=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E5=88=A4=E5=AE=9A=E6=94=B9=E7=94=A8=20isInstalled?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=AE=9A=E4=B9=89=E5=BE=AE=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=80=A7=E5=BB=BA=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit userBadges 原先用 Apps::appMenuConfig() 判定应用是否存在,每个不重复 app_id 都要解析两个 yaml(loadInstalledConfig + readPluginMenus),且 自定义微应用每行都重新 foreach setting。 - 插件应用走 Apps::isInstalled(只读一个 yaml + RequestContext 请求级缓存) - 自定义微应用循环外一次性建 id set,O(1) 命中 - 行为不变(已在线实测):installed 时正常返回;status=uninstalled 时过滤 --- app/Module/Badge.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Module/Badge.php b/app/Module/Badge.php index df508821e..29a3e127e 100644 --- a/app/Module/Badge.php +++ b/app/Module/Badge.php @@ -265,11 +265,26 @@ class Badge return $map; } $rows = AppBadge::whereUserid($userid)->get(['app_id', 'menu_key', 'count', 'dot']); + if ($rows->isEmpty()) { + return $map; + } + // 自定义微应用 id 集合一次性收,避免每行重复 foreach + $customIds = []; + $customApps = Base::setting('microapp_menu'); + if (is_array($customApps)) { + foreach ($customApps as $app) { + if (is_array($app) && !empty($app['id'])) { + $customIds[(string)$app['id']] = true; + } + } + } + // 按 app_id 缓存判定结果:插件应用走 Apps::isInstalled(单 yaml + 请求级缓存), + // 自定义微应用查 set,避免每行都读 yaml / 遍历 setting。 $exists = []; foreach ($rows as $row) { $appId = (string)$row->app_id; if (!isset($exists[$appId])) { - $exists[$appId] = Apps::appMenuConfig($appId) !== null; + $exists[$appId] = isset($customIds[$appId]) || Apps::isInstalled($appId); } if (!$exists[$appId]) { continue;