feat(publish): 街拍实体键细化为 city+year+title,支持同城同年多专题
This commit is contained in:
@ -15,7 +15,8 @@ import (
|
||||
// IngestRepository 爬虫入库管线专属仓储:任务队列(ingest_jobs)+ nonce 防重放
|
||||
// (ingest_nonces)+ 走秀正式表写入(brand_runways / brand_runway_images)。
|
||||
//
|
||||
// 实体键:走秀 = brand_id + season_code + collection_type,街拍 = city + year。
|
||||
// 实体键:走秀 = brand_id + season_code + collection_type,街拍 = city + year + title
|
||||
// (同城同年可有多个专题,title 是数据里区分专题的字段)。
|
||||
// 单表发布模型下入库直写正式表(status=pending),实体键命中后按既有行状态分三支:
|
||||
// pending/published → 放弃本次入库;rejected → 复用该行重审。因此一个秀/街拍始终只留一行。
|
||||
//
|
||||
@ -41,8 +42,9 @@ type IngestRepository interface {
|
||||
// ReuseRejectedRunway 复用一条 rejected 走秀:覆盖内容字段、软删旧图、写入新图、置回 pending(事务内完成)。
|
||||
// 驳回因此不是永久黑名单:重爬同一实体即重新送审,且始终「一个实体一行」。
|
||||
ReuseRejectedRunway(ctx context.Context, id uint32, rw *model.BrandRunway, imgs []model.BrandRunwayImage) error
|
||||
// StreetSnapEntityState 按实体键(city + year)查正式表既有行,返回其状态。
|
||||
StreetSnapEntityState(ctx context.Context, city string, year uint16) (id uint32, status string, found bool, err error)
|
||||
// StreetSnapEntityState 按实体键(city + year + title)查正式表既有行,返回其状态。
|
||||
// title 用 COALESCE 与唯一索引 uq_ss_entity 的表达式保持一致。
|
||||
StreetSnapEntityState(ctx context.Context, city string, year uint16, title string) (id uint32, status string, found bool, err error)
|
||||
// CreateStreetSnapWithImages 新建街拍正式行(status=pending)并写入图片(事务内完成)。
|
||||
CreateStreetSnapWithImages(ctx context.Context, snap *model.StreetSnap, imgs []model.StreetSnapImage) (uint32, error)
|
||||
// ReuseRejectedStreetSnap 复用一条 rejected 街拍记录(事务内完成)。
|
||||
@ -333,7 +335,11 @@ func (r *ingestRepository) ReuseRejectedRunway(ctx context.Context, id uint32, r
|
||||
})
|
||||
}
|
||||
|
||||
func (r *ingestRepository) StreetSnapEntityState(ctx context.Context, city string, year uint16) (uint32, string, bool, error) {
|
||||
// StreetSnapEntityState 按实体键(city + year + title)查正式表既有行,返回其状态。
|
||||
// title 用 COALESCE 与唯一索引 uq_ss_entity 的表达式保持一致:唯一索引里 NULL 互不冲突,
|
||||
// 若这里写成裸 title,查重口径会比索引更严,导致重爬同城同年(title 为 NULL 的历史行)时误判未命中、
|
||||
// 进而插入一行注定被索引拒绝的记录。
|
||||
func (r *ingestRepository) StreetSnapEntityState(ctx context.Context, city string, year uint16, title string) (uint32, string, bool, error) {
|
||||
var row struct {
|
||||
ID uint32 `gorm:"column:id"`
|
||||
Status string `gorm:"column:status"`
|
||||
@ -341,7 +347,7 @@ func (r *ingestRepository) StreetSnapEntityState(ctx context.Context, city strin
|
||||
err := r.db.WithContext(ctx).
|
||||
Model(&model.StreetSnap{}).
|
||||
Select("id, status").
|
||||
Where("city = ? AND year = ? AND is_deleted = 0", city, year).
|
||||
Where("city = ? AND year = ? AND COALESCE(title, '') = ? AND is_deleted = 0", city, year, title).
|
||||
Limit(1).
|
||||
Scan(&row).Error
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user