From cace078c65694be5f3d550715c99575e7570cd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Tue, 20 Oct 2026 08:22:38 +0300 Subject: [PATCH] feat(postgres):lab4 load attachment ids in ListByChat --- backend/internal/storage/postgres/message.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/internal/storage/postgres/message.go b/backend/internal/storage/postgres/message.go index 91e69f5..cbe2555 100644 --- a/backend/internal/storage/postgres/message.go +++ b/backend/internal/storage/postgres/message.go @@ -208,6 +208,25 @@ func (r *MessageRepo) ListByChat(ctx context.Context, chatID string, limit int, c := encodeCursor(scope, last.CreatedAt, last.ID) next = &c } + + if len(page) > 0 { + msgIDs := make([]string, len(page)) + for i := range page { + msgIDs[i] = page[i].ID + } + links, err := r.loadAttachmentIDs(ctx, msgIDs) + if err != nil { + return nil, nil, err + } + for i := range page { + if ids, ok := links[page[i].ID]; ok { + page[i].AttachmentIDs = ids + } else { + page[i].AttachmentIDs = []string{} + } + } + } + return page, next, nil }