fix: collectino post background

This commit is contained in:
Krispire Admin
2026-05-31 00:32:31 +05:30
parent aecdd1030a
commit 430747536d
3 changed files with 29 additions and 8 deletions
+8 -5
View File
@@ -118,7 +118,7 @@ func (r *PostRepo) FindByID(ctx context.Context, id string) (*model.Post, error)
}
return nil, fmt.Errorf("find post: %w", err)
}
imgs, err := r.imagesFor(ctx, []string{p.ID})
imgs, err := r.ImagesFor(ctx, []string{p.ID})
if err != nil {
return nil, err
}
@@ -217,7 +217,7 @@ func (r *PostRepo) collectPosts(ctx context.Context, total int, query string, ar
}
if len(ids) > 0 {
imgs, err := r.imagesFor(ctx, ids)
imgs, err := r.ImagesFor(ctx, ids)
if err != nil {
return nil, 0, err
}
@@ -228,9 +228,12 @@ func (r *PostRepo) collectPosts(ctx context.Context, total int, query string, ar
return posts, total, nil
}
// imagesFor returns a map post_id → [images...] for a batch of post IDs in
// a single query so we don't N+1 the feed endpoint.
func (r *PostRepo) imagesFor(ctx context.Context, postIDs []string) (map[string][]model.PostImage, error) {
// ImagesFor returns a map post_id → [images...] for a batch of post IDs in
// a single query so we don't N+1 the feed endpoint. Exported because the
// CollectionService needs to hydrate images onto posts that come back
// from CollectionRepo.PostsIn (which only joins posts/users — not
// post_images — to keep that query focused).
func (r *PostRepo) ImagesFor(ctx context.Context, postIDs []string) (map[string][]model.PostImage, error) {
out := make(map[string][]model.PostImage, len(postIDs))
if len(postIDs) == 0 {
return out, nil