fix(knowledge): refresh inflight items and skip empty chunked groups

Poll the knowledge item list every 5s while any item is still pending
or processing so the UI reflects ingestion progress without manual
refresh, and exclude items that have no active chunks from group
counters so groups with no usable content do not appear populated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 12:08:03 +08:00
parent 7443bb3260
commit 0a7b216513
2 changed files with 22 additions and 4 deletions
@@ -240,10 +240,20 @@ func (s *KnowledgeService) ListGroups(ctx context.Context) ([]KnowledgeGroupResp
}
countRows, err := s.pool.Query(ctx, `
SELECT group_id, COUNT(*)::bigint
FROM knowledge_items
WHERE tenant_id = $1 AND deleted_at IS NULL
GROUP BY group_id
SELECT ki.group_id, COUNT(DISTINCT ki.id)::bigint
FROM knowledge_items ki
WHERE ki.tenant_id = $1
AND ki.deleted_at IS NULL
AND ki.status = 'completed'
AND EXISTS (
SELECT 1
FROM knowledge_chunks_meta kcm
WHERE kcm.tenant_id = ki.tenant_id
AND kcm.knowledge_item_id = ki.id
AND kcm.item_version = ki.item_version
AND kcm.status = 'active'
)
GROUP BY ki.group_id
`, actor.TenantID)
if err != nil {
return nil, response.ErrInternal(50050, "knowledge_group_counts_query_failed", "failed to list knowledge group counts")