fix: rewrite sql logic
This commit is contained in:
parent
bb26cfca5b
commit
ce1b5e31d5
|
@ -80,18 +80,15 @@ func Upload(r io.ReadSeeker, size int64, hash []byte) (model.Upload, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
result := db.Get().Where(&model.Upload{Hash: hashHex}).First(&upload)
|
result := db.Get().Where(&model.Upload{Hash: hashHex}).First(&upload)
|
||||||
if (result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound)) || result.RowsAffected > 0 {
|
if !errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
err := result.Row().Scan(&upload)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Get().Error(ErrFailedQueryUpload.Error(), zap.Error(err))
|
logger.Get().Error(ErrFailedQueryUpload.Error(), zap.Error(err))
|
||||||
return upload, ErrFailedQueryUpload
|
return upload, ErrFailedQueryUpload
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.RowsAffected > 0 && upload.ID > 0 {
|
|
||||||
logger.Get().Info(ErrAlreadyExists.Error())
|
logger.Get().Info(ErrAlreadyExists.Error())
|
||||||
return upload, nil
|
return upload, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
objectExistsResult, err := client.R().Get(getBusObjectUrl(hashHex))
|
objectExistsResult, err := client.R().Get(getBusObjectUrl(hashHex))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue