Development SDK of Paperclip

 Support update usage by random id
This commit is contained in:
2025-03-10 23:11:12 +08:00
parent 38aa06cc00
commit 1d866f317f
5 changed files with 109 additions and 51 deletions

View File

@ -318,9 +318,8 @@ func DeleteAttachmentInBatch(items []models.Attachment, txs ...*gorm.DB) error {
return nil
}
func CountAttachmentUsage(id []uint, delta int) (int64, error) {
if tx := database.C.Model(&models.Attachment{}).
Where("id IN ?", id).
func CountAttachmentUsage(tx *gorm.DB, delta int) (int64, error) {
if tx := tx.Model(&models.Attachment{}).
Update("used_count", gorm.Expr("used_count + ?", delta)); tx.Error != nil {
return tx.RowsAffected, tx.Error
} else {