by Robin at 20240308

This commit is contained in:
Leufolium 2024-03-08 22:36:16 +08:00
parent 43138ec16d
commit db9d6b2b0b
1 changed files with 22 additions and 6 deletions

View File

@ -432,6 +432,11 @@ func (s *Service) utilGetFollowMap(ctx *gin.Context, visitorMid int64) (_map map
}
func (s *Service) utilFillIsFollowedFillable(ctx *gin.Context, visitorFollowMap map[int64]*dbstruct.AccountRelation, isFollowedFillable interfaces.IsFollowedFillable) {
mids := make([]int64, 0)
for k, _ := range visitorFollowMap {
mids = append(mids, k)
}
logger.Info("mids: %v, obj_mid: %v", mids, isFollowedFillable.GetMid())
if visitorFollowMap[isFollowedFillable.GetMid()] != nil {
isFollowedFillable.SetIsFollowed(consts.IsFollowed_Yes)
} else {
@ -1105,20 +1110,31 @@ func (s *Service) utilGetMomentRecommListVO(ctx *gin.Context, recommlist []int64
}
// 根据用户游标查询得到结果
midList := make([]int64, 0)
idList := make([]int64, 0)
for i := 0; i < upperBound; i++ {
index := (offset + int64(i)) % int64(recommListLength)
midList = append(midList, recommlist[index])
idList = append(idList, recommlist[index])
}
list, err := _DefaultMoment.OpListByIds(ctx, &momentproto.OpListByIdsReq{
Ids: midList,
Ids: idList,
})
if err != nil {
logger.Error("_DefaultMoment OpListByIds fail, , err: %v", err)
return
}
// list -> idList 索引的map
_momentIndexMap := make(map[int]int)
for i, account := range list {
id1 := util.DerefInt64(account.Id)
for j, id2 := range idList {
if id1 == id2 {
_momentIndexMap[i] = j
}
}
}
// 获取访问者的关注列表
followMap, err := s.utilGetFollowMap(ctx, mid)
if err != nil {
@ -1132,8 +1148,8 @@ func (s *Service) utilGetMomentRecommListVO(ctx *gin.Context, recommlist []int64
logger.Error("utilFillMomentsStreamerInfo fail, , err: %v", err)
return
}
recommMomentList = make([]*momentproto.ApiMomentVO, 0)
for _, vo := range vos {
recommMomentList = make([]*momentproto.ApiMomentVO, len(vos))
for i, vo := range vos {
apiVO, _ := vo.(*momentproto.ApiMomentVO)
// 填充是否关注
s.utilFillIsFollowedFillable(ctx, followMap, apiVO)
@ -1142,7 +1158,7 @@ func (s *Service) utilGetMomentRecommListVO(ctx *gin.Context, recommlist []int64
logger.Error("utilFillIsThumbedUpFillable fail")
return
}
recommMomentList = append(recommMomentList, apiVO)
recommMomentList[_momentIndexMap[i]] = apiVO
}
return