fix: rewrite sql logic

This commit is contained in:
Derrick Hammer 2023-06-11 03:57:56 -04:00
parent bb26cfca5b
commit ce1b5e31d5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 6 deletions

View File

@ -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))