fix v13
This commit is contained in:
@@ -114,7 +114,19 @@ func runHidePublic(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
result := build().Update("is_private", true)
|
||||
// ⚠️ 必须先快照目标 ID 再更新:build() 的条件里有 is_private = false,
|
||||
// 一旦执行了 Update,再拿 build() 当子查询就恒为空集,举报闭环会静默失效
|
||||
// (实测:隐藏成功但 content_reports 仍是 pending)。
|
||||
var targetIDs []uint
|
||||
if err := build().Pluck("id", &targetIDs).Error; err != nil {
|
||||
return errors.Wrap(err, "collect target question ids")
|
||||
}
|
||||
if len(targetIDs) == 0 {
|
||||
fmt.Println("没有需要隐藏的内容")
|
||||
return nil
|
||||
}
|
||||
|
||||
result := database.Model(&db.Question{}).Where("id IN ?", targetIDs).Update("is_private", true)
|
||||
if result.Error != nil {
|
||||
return errors.Wrap(result.Error, "hide public questions")
|
||||
}
|
||||
@@ -129,7 +141,7 @@ func runHidePublic(ctx *cli.Context) error {
|
||||
// 否则这些举报会继续计入告警阈值(详见 internal/db/report.go 的说明)。
|
||||
accepted := database.WithContext(ctx.Context).
|
||||
Model(&db.ContentReport{}).
|
||||
Where("question_id IN (?)", build().Select("id")).
|
||||
Where("question_id IN ?", targetIDs).
|
||||
Where("status = ?", db.ReportStatusPending).
|
||||
Update("status", db.ReportStatusAccepted)
|
||||
if accepted.Error != nil {
|
||||
|
||||
Reference in New Issue
Block a user