perf: batch tag reference counting

This commit is contained in:
wizardchen
2026-01-20 11:42:34 +08:00
committed by lyingbug
parent a6ba12f389
commit b1895f7443
4 changed files with 96 additions and 11 deletions
+8
View File
@@ -52,6 +52,14 @@ type KnowledgeTagRepository interface {
kbID string,
tagID string,
) (knowledgeCount int64, chunkCount int64, err error)
// BatchCountReferences returns number of knowledges and chunks for multiple tags in a single query.
// Returns a map of tagID -> {knowledgeCount, chunkCount}
BatchCountReferences(
ctx context.Context,
tenantID uint64,
kbID string,
tagIDs []string,
) (map[string]types.TagReferenceCounts, error)
// DeleteUnusedTags deletes tags that are not referenced by any knowledge or chunk.
DeleteUnusedTags(ctx context.Context, tenantID uint64, kbID string) (int64, error)
}
+6
View File
@@ -32,3 +32,9 @@ type KnowledgeTagWithStats struct {
KnowledgeCount int64 `json:"knowledge_count"`
ChunkCount int64 `json:"chunk_count"`
}
// TagReferenceCounts holds the reference counts for a tag.
type TagReferenceCounts struct {
KnowledgeCount int64
ChunkCount int64
}