From 0c7d2d740010259475924b75444d7e045fa8c418 Mon Sep 17 00:00:00 2001 From: simonkoson <28867558@qq.com> Date: Wed, 27 May 2026 15:00:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20type=5Fgroups=E5=8A=A8=E6=80=81=E6=94=B6?= =?UTF-8?q?=E9=9B=86=EF=BC=8C=E7=A9=BA=E5=A4=A7=E7=B1=BB=E4=BB=8E=E6=A0=B9?= =?UTF-8?q?=E4=B8=8A=E4=B8=8D=E4=BA=A7=E7=94=9F=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/knowledge_service.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/app/services/knowledge_service.py b/backend/app/services/knowledge_service.py index b9051e0..3e976d1 100644 --- a/backend/app/services/knowledge_service.py +++ b/backend/app/services/knowledge_service.py @@ -282,20 +282,20 @@ class KnowledgeService: total_count = len(items) - # 按 source_type 分组,初始化所有已知类别 - type_groups: dict = {st: [] for st in self.SOURCE_TYPE_ORDER} + # 按 source_type 分组:仅收集有数据的类别,再按固定顺序排列 + type_groups: dict = {} for item in items: st = item.source_type or "manual" if st not in type_groups: type_groups[st] = [] type_groups[st].append(item) + # 只遍历有数据的类别,按 SOURCE_TYPE_ORDER 顺序 children = [] for st in self.SOURCE_TYPE_ORDER: - st_items = type_groups.get(st, []) - # 空类别(0条)不渲染 - if not st_items: + if st not in type_groups: continue + st_items = type_groups[st] secondary_field = self.SECONDARY_GROUP_FIELD.get(st) grandchildren = []