Preload thumbnail, compressed

This commit is contained in:
LittleSheep 2024-12-28 15:45:31 +08:00
parent 845894f12c
commit 0c33c2d86c
2 changed files with 11 additions and 2 deletions

View File

@ -84,7 +84,10 @@ func listAttachment(c *fiber.Ctx) error {
if needQuery { if needQuery {
var out []models.Attachment var out []models.Attachment
if err := tx.Offset(offset).Limit(take).Find(&out).Error; err != nil { if err := tx.
Offset(offset).Limit(take).
Preload("Thumbnail").Preload("Compressed").
Find(&out).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} }

View File

@ -33,6 +33,8 @@ func GetAttachmentByID(id uint) (models.Attachment, error) {
if err := database.C. if err := database.C.
Where("id = ?", id). Where("id = ?", id).
Preload("Pool"). Preload("Pool").
Preload("Thumbnail").
Preload("Compressed").
First(&attachment).Error; err != nil { First(&attachment).Error; err != nil {
return attachment, err return attachment, err
} else { } else {
@ -58,7 +60,11 @@ func GetAttachmentByRID(rid string) (models.Attachment, error) {
var attachment models.Attachment var attachment models.Attachment
if err := database.C.Where(models.Attachment{ if err := database.C.Where(models.Attachment{
Rid: rid, Rid: rid,
}).Preload("Pool").First(&attachment).Error; err != nil { }).
Preload("Pool").
Preload("Thumbnail").
Preload("Compressed").
First(&attachment).Error; err != nil {
return attachment, err return attachment, err
} else { } else {
CacheAttachment(attachment) CacheAttachment(attachment)