feat: 新增FAQ列表排序功能,支持按更新时间升序/降序排列;优化标签名称批量查询,提升查询效率

This commit is contained in:
wizardchen
2025-12-24 11:00:57 +08:00
parent 529b31da23
commit b2eec004c9
14 changed files with 88 additions and 9 deletions
+8 -1
View File
@@ -78,6 +78,7 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
chunkType []types.ChunkType,
tagID string,
keyword string,
sortOrder string,
) ([]*types.Chunk, int64, error) {
var chunks []*types.Chunk
var total int64
@@ -109,8 +110,14 @@ func (r *chunkRepository) ListPagedChunksByKnowledgeID(
// Then query the paginated data
dataQuery := baseFilter(r.db.WithContext(ctx))
// Default is time descending, "asc" for time ascending
orderClause := "updated_at DESC"
if sortOrder == "asc" {
orderClause = "updated_at ASC"
}
if err := dataQuery.
Order("chunk_index ASC").
Order(orderClause).
Offset(page.Offset()).
Limit(page.Limit()).
Find(&chunks).Error; err != nil {
+14
View File
@@ -40,6 +40,20 @@ func (r *knowledgeTagRepository) GetByID(ctx context.Context, tenantID uint64, i
return &tag, nil
}
// GetByIDs retrieves multiple tags by their IDs in a single query
func (r *knowledgeTagRepository) GetByIDs(ctx context.Context, tenantID uint64, ids []string) ([]*types.KnowledgeTag, error) {
if len(ids) == 0 {
return []*types.KnowledgeTag{}, nil
}
var tags []*types.KnowledgeTag
if err := r.db.WithContext(ctx).
Where("tenant_id = ? AND id IN (?)", tenantID, ids).
Find(&tags).Error; err != nil {
return nil, err
}
return tags, nil
}
// GetByName gets a knowledge tag by name
func (r *knowledgeTagRepository) GetByName(ctx context.Context, tenantID uint64, kbID string, name string) (*types.KnowledgeTag, error) {
var tag types.KnowledgeTag