feat(hot-rank): add per-channel hot ranking functionality
Add channel-specific hot post filtering and ranking across the posts listing flow. Introduce refreshChannelRanks to compute per-channel hot scores, new Redis cache keys for channel hot ranks, and update repository/service/handler layers to accept channelID filtering parameters. Update HotRankWorker dependency injection to include ChannelRepository.
This commit is contained in:
@@ -293,24 +293,20 @@ func (h *PostHandler) List(c *gin.Context) {
|
||||
// 根据 tab 参数选择不同的获取方式
|
||||
switch tab {
|
||||
case "follow":
|
||||
// 获取关注用户的帖子,需要登录
|
||||
if currentUserID == "" {
|
||||
response.Unauthorized(c, "请先登录")
|
||||
return
|
||||
}
|
||||
posts, total, err = h.postService.GetFollowingPosts(c.Request.Context(), currentUserID, page, pageSize)
|
||||
posts, total, err = h.postService.GetFollowingPosts(c.Request.Context(), currentUserID, page, pageSize, channelID)
|
||||
case "hot":
|
||||
// 获取热门帖子
|
||||
posts, total, err = h.postService.GetHotPosts(c.Request.Context(), page, pageSize)
|
||||
posts, total, err = h.postService.GetHotPosts(c.Request.Context(), page, pageSize, channelID)
|
||||
case "latest":
|
||||
// 最新帖子
|
||||
if userID != "" && userID == currentUserID {
|
||||
posts, total, err = h.postService.GetLatestPostsForOwner(c.Request.Context(), page, pageSize, userID, channelID)
|
||||
} else {
|
||||
posts, total, err = h.postService.GetLatestPosts(c.Request.Context(), page, pageSize, userID, channelID)
|
||||
}
|
||||
default:
|
||||
// 默认获取最新帖子
|
||||
if userID != "" && userID == currentUserID {
|
||||
posts, total, err = h.postService.GetLatestPostsForOwner(c.Request.Context(), page, pageSize, userID, channelID)
|
||||
} else {
|
||||
@@ -360,15 +356,13 @@ func (h *PostHandler) ListByCursor(c *gin.Context) {
|
||||
// 根据 tab 参数选择不同的获取方式
|
||||
switch tab {
|
||||
case "follow":
|
||||
// 获取关注用户的帖子,需要登录
|
||||
if currentUserID == "" {
|
||||
response.Unauthorized(c, "请先登录")
|
||||
return
|
||||
}
|
||||
result, err = h.postService.GetFollowingPostsByCursor(c.Request.Context(), currentUserID, req)
|
||||
result, err = h.postService.GetFollowingPostsByCursor(c.Request.Context(), currentUserID, channelID, req)
|
||||
case "hot":
|
||||
// 获取热门帖子
|
||||
result, err = h.postService.GetHotPostsByCursor(c.Request.Context(), req)
|
||||
result, err = h.postService.GetHotPostsByCursor(c.Request.Context(), channelID, req)
|
||||
case "latest":
|
||||
// 最新帖子
|
||||
result, err = h.postService.ListByCursor(c.Request.Context(), userID, includePending, channelID, req)
|
||||
|
||||
Reference in New Issue
Block a user