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 {
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())
}

View File

@ -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)