♻️ Use update api instead of overhaul in background tasks
This commit is contained in:
parent
2bd8dc17d1
commit
5e73d9acd4
@ -220,16 +220,14 @@ func AnalyzeAttachment(file models.Attachment) error {
|
|||||||
|
|
||||||
tx := database.C.Begin()
|
tx := database.C.Begin()
|
||||||
|
|
||||||
file.IsAnalyzed = true
|
if err := tx.Model(&file).Update("is_analyzed", true).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return fmt.Errorf("unable to update file record: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
linked, err := TryLinkAttachment(tx, file, file.HashCode)
|
linked, err := TryLinkAttachment(tx, file, file.HashCode)
|
||||||
if linked && err != nil {
|
if linked && err != nil {
|
||||||
return fmt.Errorf("unable to link file record: %v", err)
|
return fmt.Errorf("unable to link file record: %v", err)
|
||||||
} else if !linked {
|
|
||||||
if err := tx.Save(&file).Error; err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return fmt.Errorf("unable to save file record: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
@ -166,19 +166,15 @@ func TryLinkAttachment(tx *gorm.DB, og models.Attachment, hash string) (bool, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev.RefCount++
|
if err := tx.Model(&og).Updates(&models.Attachment{
|
||||||
og.RefID = &prev.ID
|
RefID: &prev.ID,
|
||||||
og.Uuid = prev.Uuid
|
Uuid: prev.Uuid,
|
||||||
og.Destination = prev.Destination
|
Destination: prev.Destination,
|
||||||
|
IsSelfRef: og.AccountID == prev.AccountID,
|
||||||
if og.AccountID == prev.AccountID {
|
}).Error; err != nil {
|
||||||
og.IsSelfRef = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tx.Save(&og).Error; err != nil {
|
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return true, err
|
return true, err
|
||||||
} else if err = tx.Save(&prev).Error; err != nil {
|
} else if err = tx.Model(&prev).Update("ref_count", prev.RefCount+1).Error; err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func ReUploadFile(meta models.Attachment, dst int, doNotUpdate ...bool) error {
|
|||||||
|
|
||||||
cleanupDst := func() {
|
cleanupDst := func() {
|
||||||
if len(doNotUpdate) == 0 || !doNotUpdate[0] {
|
if len(doNotUpdate) == 0 || !doNotUpdate[0] {
|
||||||
database.C.Save(&meta)
|
database.C.Model(&meta).Update("destination", dst)
|
||||||
}
|
}
|
||||||
if prevDst == models.AttachmentDstTemporary {
|
if prevDst == models.AttachmentDstTemporary {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user