From 5a93be8dbd29034b241b5da2823ab99de1bae41f Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 14 Jan 2026 10:45:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=A0=87=E7=AD=BE=E6=97=B6=E5=BF=BD=E7=95=A5=E5=B7=B2?= =?UTF-8?q?=E8=BD=AF=E5=88=A0=E9=99=A4=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/repository/tag.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/application/repository/tag.go b/internal/application/repository/tag.go index c90a59db..d7eea5dc 100644 --- a/internal/application/repository/tag.go +++ b/internal/application/repository/tag.go @@ -164,11 +164,11 @@ func (r *knowledgeTagRepository) CountReferences( // DeleteUnusedTags deletes tags that are not referenced by any knowledge or chunk. // Returns the number of deleted tags. func (r *knowledgeTagRepository) DeleteUnusedTags(ctx context.Context, tenantID uint64, kbID string) (int64, error) { - // Delete tags that have no references in both knowledges and chunks tables + // Delete tags that have no references in both knowledges and chunks tables (excluding soft-deleted records) result := r.db.WithContext(ctx). Where("tenant_id = ? AND knowledge_base_id = ?", tenantID, kbID). - Where("id NOT IN (SELECT DISTINCT tag_id FROM knowledges WHERE tenant_id = ? AND knowledge_base_id = ? AND tag_id IS NOT NULL AND tag_id != '')", tenantID, kbID). - Where("id NOT IN (SELECT DISTINCT tag_id FROM chunks WHERE tenant_id = ? AND knowledge_base_id = ? AND tag_id IS NOT NULL AND tag_id != '')", tenantID, kbID). + Where("id NOT IN (SELECT DISTINCT tag_id FROM knowledges WHERE tenant_id = ? AND knowledge_base_id = ? AND tag_id IS NOT NULL AND tag_id != '' AND deleted_at IS NULL)", tenantID, kbID). + Where("id NOT IN (SELECT DISTINCT tag_id FROM chunks WHERE tenant_id = ? AND knowledge_base_id = ? AND tag_id IS NOT NULL AND tag_id != '' AND deleted_at IS NULL)", tenantID, kbID). Delete(&types.KnowledgeTag{}) return result.RowsAffected, result.Error }