🐛 Only apply active boost

This commit is contained in:
LittleSheep 2024-12-29 12:23:41 +08:00
parent c6944cd3df
commit a58f44d50e
2 changed files with 11 additions and 2 deletions

View File

@ -44,6 +44,16 @@ func ListBoostByAttachment(attachmentId uint) ([]models.AttachmentBoost, error)
return boosts, nil return boosts, nil
} }
func ListBoostByAttachmentWithStatus(attachmentId uint, status int) ([]models.AttachmentBoost, error) {
var boosts []models.AttachmentBoost
if err := database.C.
Where("attachment_id = ? AND status = ?", attachmentId, status).
Find(&boosts).Error; err != nil {
return boosts, err
}
return boosts, nil
}
func GetBoostByID(id uint) (models.AttachmentBoost, error) { func GetBoostByID(id uint) (models.AttachmentBoost, error) {
var boost models.AttachmentBoost var boost models.AttachmentBoost
if err := database.C. if err := database.C.

View File

@ -52,13 +52,12 @@ func OpenAttachmentByRID(rid string, region ...string) (url string, mimetype str
Preload("Pool"). Preload("Pool").
Preload("Thumbnail"). Preload("Thumbnail").
Preload("Compressed"). Preload("Compressed").
Preload("Boosts").
First(&attachment).Error; err != nil { First(&attachment).Error; err != nil {
return return
} }
var boosts []models.AttachmentBoost var boosts []models.AttachmentBoost
boosts, err = ListBoostByAttachment(attachment.ID) boosts, err = ListBoostByAttachmentWithStatus(attachment.ID, models.BoostStatusActive)
if err != nil { if err != nil {
return return
} }