feat(models): 对齐 vivid 新改动——模型删除改软删,重导不丢计数/定价
- model_configs 加 deleted_at(gorm 软删),List/Get 自动过滤, GetAny/Unscoped 用于复活与孤儿清理路径 - 渠道同步/删渠道/管理端删除模型的孤儿清理全部走软删 - 导入时若命中软删行:UpdateAny + deleted_at=NULL 复活, generation_count 与原定价保留(vivid a42f32c 同语义) - provider 时代残留仍物理删除(DeleteHard),不留软删垃圾 - OrphanModelIDs 跳过已软删行,避免重复清扫 - btn-primary 禁用态改浅灰填充(vivid d636105) 核对过已等价的:vivid 僵尸任务兜底(我们的 ResumeStaleJob+ PurgeStale+MarkRefunded 同语义)、产物 MIME 魔数嗅探、 retention 按创建时间、渠道同步弹窗(开关+别名)均已覆盖。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -381,11 +381,12 @@ func (s *ChannelService) PurgeOrphanModels(ctx context.Context) (int, error) {
|
||||
}
|
||||
n := 0
|
||||
for _, id := range ids {
|
||||
m, gerr := s.models.Get(ctx, id)
|
||||
m, gerr := s.models.GetAny(ctx, id)
|
||||
if gerr != nil || m == nil || m.Provider == "channel" {
|
||||
continue
|
||||
}
|
||||
if _, derr := s.models.Delete(ctx, id); derr == nil {
|
||||
// provider 时代残留行没有复活路径,直接物理删除,不留软删垃圾。
|
||||
if _, derr := s.models.DeleteHard(ctx, id); derr == nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
@@ -454,7 +455,8 @@ func (s *ChannelService) ImportModels(ctx context.Context, channelID string, spe
|
||||
return fmt.Errorf("别名 %s 被多个上游模型复用", localID)
|
||||
}
|
||||
seenAliases[localID] = upID
|
||||
existing, gerr := s.models.Get(ctx, localID)
|
||||
// GetAny: 软删行也纳入——重导同一模型时复活原行,计数/定价不丢。
|
||||
existing, gerr := s.models.GetAny(ctx, localID)
|
||||
if gerr != nil && !errors.Is(gerr, gorm.ErrRecordNotFound) {
|
||||
existing = nil
|
||||
}
|
||||
@@ -481,7 +483,10 @@ func (s *ChannelService) ImportModels(ctx context.Context, channelID string, spe
|
||||
return fmt.Errorf("model %s: %w", localID, err)
|
||||
}
|
||||
} else {
|
||||
if _, err := s.models.Update(ctx, localID, patch); err != nil {
|
||||
if local.DeletedAt.Valid {
|
||||
patch["deleted_at"] = nil // revive
|
||||
}
|
||||
if _, err := s.models.UpdateAny(ctx, localID, patch); err != nil {
|
||||
return fmt.Errorf("model %s: %w", localID, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user