From 168c089456da8bb77ccce18cd9440151fb18bef0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 26 Jul 2024 16:42:16 +0800 Subject: [PATCH] :bug: Fix fixes on listing attachments and improve performance --- pkg/internal/server/api/attachment_dir_api.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/internal/server/api/attachment_dir_api.go b/pkg/internal/server/api/attachment_dir_api.go index aec5767..2ad216b 100644 --- a/pkg/internal/server/api/attachment_dir_api.go +++ b/pkg/internal/server/api/attachment_dir_api.go @@ -18,11 +18,13 @@ func listAttachment(c *fiber.Ctx) error { tx := database.C - var author models.Account - if err := database.C.Where("name = ?", c.Query("author")).Error; err != nil { - return fiber.NewError(fiber.StatusBadRequest, err.Error()) - } else { - tx = tx.Where("account_id = ?", author.ID) + if len(c.Query("author")) > 0 { + var author models.Account + if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil { + return fiber.NewError(fiber.StatusBadRequest, err.Error()) + } else { + tx = tx.Where("account_id = ?", author.ID) + } } if usage := strings.Split(c.Query("usage"), " "); len(usage) > 0 {