From 0c33c2d86ce2c91db7de5c79ec2a3ad7edf50cfc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 28 Dec 2024 15:45:31 +0800 Subject: [PATCH] :sparkles: Preload thumbnail, compressed --- pkg/internal/server/api/index_api.go | 5 ++++- pkg/internal/services/attachments.go | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/internal/server/api/index_api.go b/pkg/internal/server/api/index_api.go index cf38a53..18655b3 100644 --- a/pkg/internal/server/api/index_api.go +++ b/pkg/internal/server/api/index_api.go @@ -84,7 +84,10 @@ func listAttachment(c *fiber.Ctx) error { if needQuery { 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()) } diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go index fe1e859..3921967 100644 --- a/pkg/internal/services/attachments.go +++ b/pkg/internal/services/attachments.go @@ -33,6 +33,8 @@ func GetAttachmentByID(id uint) (models.Attachment, error) { if err := database.C. Where("id = ?", id). Preload("Pool"). + Preload("Thumbnail"). + Preload("Compressed"). First(&attachment).Error; err != nil { return attachment, err } else { @@ -58,7 +60,11 @@ func GetAttachmentByRID(rid string) (models.Attachment, error) { var attachment models.Attachment if err := database.C.Where(models.Attachment{ Rid: rid, - }).Preload("Pool").First(&attachment).Error; err != nil { + }). + Preload("Pool"). + Preload("Thumbnail"). + Preload("Compressed"). + First(&attachment).Error; err != nil { return attachment, err } else { CacheAttachment(attachment)