优化结构
This commit is contained in:
@@ -116,18 +116,18 @@ func (r *mediaRepo) ListChunks(ctx context.Context, uploadID uint) ([]*system.Up
|
||||
return out, nil
|
||||
}
|
||||
func (r *mediaRepo) DeleteChunks(ctx context.Context, uploadID uint) error {
|
||||
return r.data.DB().WithContext(ctx).Where("upload_id = ?", uploadID).Delete(&uploadChunkPO{}).Error
|
||||
return r.data.DB().WithContext(ctx).Unscoped().Where("upload_id = ?", uploadID).Delete(&uploadChunkPO{}).Error
|
||||
}
|
||||
func (r *mediaRepo) StaleUploadSessionIDs(ctx context.Context, before time.Time) ([]uint, error) {
|
||||
var ids []uint
|
||||
err := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("status IN ? AND updated_at < ?", []string{"uploading", "failed", "merging"}, before).Pluck("id", &ids).Error
|
||||
err := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("(status IN ? AND updated_at < ?) OR (status = ? AND updated_at < ?)", []string{"uploading", "failed"}, before, "merging", before.Add(-time.Hour)).Pluck("id", &ids).Error
|
||||
return ids, err
|
||||
}
|
||||
func (r *mediaRepo) DeleteUploadData(ctx context.Context, uploadID uint) error {
|
||||
return r.data.DB().WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Where("upload_id = ?", uploadID).Delete(&uploadChunkPO{}).Error; err != nil {
|
||||
if err := tx.Unscoped().Where("upload_id = ?", uploadID).Delete(&uploadChunkPO{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Delete(&uploadSessionPO{}, uploadID).Error
|
||||
return tx.Unscoped().Delete(&uploadSessionPO{}, uploadID).Error
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user