MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / ListPosts

Method ListPosts

internal/repository/post.go:165–194  ·  view source on GitHub ↗

ListPosts 获取作者帖子的列表

(ctx context.Context, pagination domain.Pagination)

Source from the content-addressed store, hash-verified

163
164// ListPosts 获取作者帖子的列表
165func (p *postRepository) ListPosts(ctx context.Context, pagination domain.Pagination) ([]domain.Post, error) {
166 // 先从缓存中获取
167 posts, err := p.cache.GetList(ctx, pagination.Page, int(*pagination.Size))
168 if err == nil && len(posts) > 0 {
169 return posts, nil
170 }
171
172 // 缓存未命中,从数据库获取
173 pub, err := p.dao.List(ctx, pagination)
174 if err != nil {
175 p.l.Error("获取帖子列表失败",
176 zap.Error(err),
177 zap.Int("page", pagination.Page))
178 return nil, fmt.Errorf("获取帖子列表失败: %w", err)
179 }
180
181 // 转换数据
182 result := change.FromDomainSlicePost(pub)
183
184 // 异步写入缓存
185 go func() {
186 if err := p.cache.SetList(ctx, pagination.Page, int(*pagination.Size), result); err != nil {
187 p.l.Error("缓存帖子列表失败",
188 zap.Error(err),
189 zap.Int("page", pagination.Page))
190 }
191 }()
192
193 return result, nil
194}
195
196// ListPublishPosts 获取已发布的帖子列表
197func (p *postRepository) ListPublishPosts(ctx context.Context, pagination domain.Pagination, biz ...int) ([]domain.Post, error) {

Callers

nothing calls this directly

Calls 4

FromDomainSlicePostFunction · 0.92
GetListMethod · 0.65
ListMethod · 0.65
SetListMethod · 0.65

Tested by

no test coverage detected