update
This commit is contained in:
@ -21,6 +21,10 @@ type BrandRepository interface {
|
||||
// 按 metric(images = 图片总数 / shows = 发布会数)排名取前 limit 个。
|
||||
FeaturedIDs(ctx context.Context, metric string, limit int) ([]uint32, error)
|
||||
|
||||
// ListByIDs 按 id 集合取品牌行(不保证顺序,调用方按热度自行重排)。
|
||||
// 供 Hot 等已知 id 列表的场景使用,避免借道 List 的 featured 旗标复用查询。
|
||||
ListByIDs(ctx context.Context, ids []uint32) ([]model.Brand, error)
|
||||
|
||||
// ArticleCountByBrandIDs 批量统计各品牌的走秀档案数,单次分组查询避免 N+1。
|
||||
ArticleCountByBrandIDs(ctx context.Context, ids []uint32) (map[uint32]int, error)
|
||||
|
||||
@ -81,7 +85,9 @@ func (r *brandRepository) brandFilterScope(q dto.BrandQuery, restrictIDs []uint3
|
||||
}
|
||||
|
||||
// 中文分桶不限档案,直接列出全部中文名品牌,便于检索
|
||||
if q.OnlyWithArticles && q.Letter != "OTHER" {
|
||||
// 关键词搜索时不限制"必须有走秀档案":用户按名字找品牌,
|
||||
// 即使该品牌暂无走秀档案也应被命中(如 A Bathing Ape / 猿人头)。
|
||||
if q.OnlyWithArticles && q.Keyword == "" && q.Letter != "OTHER" {
|
||||
db = db.Where("id IN (?)", r.hasArticlesSubQuery())
|
||||
}
|
||||
|
||||
@ -157,6 +163,20 @@ func (r *brandRepository) FeaturedIDs(ctx context.Context, metric string, limit
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// ListByIDs 按 id 集合取品牌行;MySQL IN 查询不保证返回顺序,调用方自行重排。
|
||||
func (r *brandRepository) ListByIDs(ctx context.Context, ids []uint32) ([]model.Brand, error) {
|
||||
if len(ids) == 0 {
|
||||
return []model.Brand{}, nil
|
||||
}
|
||||
var items []model.Brand
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("is_deleted = 0 AND id IN ?", ids).
|
||||
Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (r *brandRepository) ArticleCountByBrandIDs(ctx context.Context, ids []uint32) (map[uint32]int, error) {
|
||||
counts := make(map[uint32]int, len(ids))
|
||||
if len(ids) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user