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

Method GetPublishPostById

internal/repository/post.go:136–162  ·  view source on GitHub ↗

GetPublishPostById 获取已发布的帖子详细信息

(ctx context.Context, postId uint)

Source from the content-addressed store, hash-verified

134
135// GetPublishPostById 获取已发布的帖子详细信息
136func (p *postRepository) GetPublishPostById(ctx context.Context, postId uint) (domain.Post, error) {
137 // 先从缓存中获取
138 post, err := p.cache.GetPub(ctx, strconv.Itoa(int(postId)))
139 if err == nil {
140 return post, nil
141 }
142
143 dp, err := p.dao.GetPubById(ctx, postId)
144 if err != nil {
145 p.l.Error("获取已发布帖子失败", zap.Error(err), zap.Uint("post_id", postId))
146 // 缓存空对象
147 if err := p.cache.SetEmpty(ctx, fmt.Sprint(postId)); err != nil {
148 p.l.Error("设置空对象缓存失败", zap.Error(err))
149 }
150 return domain.Post{}, err
151 }
152
153 result := change.ToDomainPubPost(dp)
154
155 go func() {
156 if err := p.cache.SetPub(ctx, strconv.Itoa(int(postId)), result); err != nil {
157 p.l.Error("设置已发布帖子缓存失败", zap.Error(err), zap.Uint("post_id", postId))
158 }
159 }()
160
161 return result, nil
162}
163
164// ListPosts 获取作者帖子的列表
165func (p *postRepository) ListPosts(ctx context.Context, pagination domain.Pagination) ([]domain.Post, error) {

Callers

nothing calls this directly

Calls 5

ToDomainPubPostFunction · 0.92
GetPubMethod · 0.65
GetPubByIdMethod · 0.65
SetEmptyMethod · 0.65
SetPubMethod · 0.65

Tested by

no test coverage detected