fix(apps): 角标快照过滤已卸载应用的残留行

应用卸载后 app_badges 表行未被清理(主程序侧无卸载回调),
导致 hydrate 后父级『应用』入口聚合仍把残留 count 算进去。

userBadges 返回前用 Apps::appMenuConfig() 判定应用是否仍存在
(同时覆盖插件应用与自定义微应用),不存在则跳过;按 app_id 缓
存判定结果,避免逐行重复读 yaml。
This commit is contained in:
kuaifan 2026-06-29 12:16:19 +00:00
parent 09439b555c
commit 4a18ff0315

View File

@ -253,6 +253,7 @@ class Badge
/**
* 获取用户当前全部角标快照,用于前端初始同步。
* 过滤掉应用已不存在(卸载 / 自定义微应用被删除)的行,避免父级聚合统计残留数据。
*
* @param int $userid
* @return array app_id => menu_key => ['count'=>int,'dot'=>bool]
@ -264,8 +265,16 @@ class Badge
return $map;
}
$rows = AppBadge::whereUserid($userid)->get(['app_id', 'menu_key', 'count', 'dot']);
$exists = [];
foreach ($rows as $row) {
$map[$row->app_id][$row->menu_key] = [
$appId = (string)$row->app_id;
if (!isset($exists[$appId])) {
$exists[$appId] = Apps::appMenuConfig($appId) !== null;
}
if (!$exists[$appId]) {
continue;
}
$map[$appId][$row->menu_key] = [
'count' => (int)$row->count,
'dot' => (bool)$row->dot,
];