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

Method GetTopCommentsReply

internal/repository/comment.go:72–93  ·  view source on GitHub ↗

GetTopCommentsReply 加载顶级评论

(ctx context.Context, postId int64)

Source from the content-addressed store, hash-verified

70
71// GetTopCommentsReply 加载顶级评论
72func (c *commentRepository) GetTopCommentsReply(ctx context.Context, postId int64) (domain.Comment, error) {
73 // 优先从缓存获取
74 if comments, err := c.cache.Get(ctx, postId); err == nil {
75 return comments, nil
76 } else if err != redis.Nil {
77 return domain.Comment{}, fmt.Errorf("获取缓存失败: %w", err)
78 }
79
80 // 缓存未命中,从数据库加载
81 daoComments, err := c.dao.FindTopCommentsByPostId(ctx, postId)
82 if err != nil {
83 return domain.Comment{}, fmt.Errorf("从数据库加载评论失败: %w", err)
84 }
85
86 // 转换并写入缓存
87 domainComment := c.toDomainComment(daoComments)
88 if err := c.cache.Set(ctx, domainComment); err != nil {
89 return domain.Comment{}, fmt.Errorf("写入缓存失败: %w", err)
90 }
91
92 return domainComment, nil
93}
94
95// ListComments 列出评论
96func (c *commentRepository) ListComments(ctx context.Context, postId int64, minId, limit int64) ([]domain.Comment, error) {

Callers

nothing calls this directly

Calls 4

toDomainCommentMethod · 0.95
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected