feat(postgres):lab4 load attachment ids in ListByChat
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user