From db9d6b2b0becb0587de6cb72971dd3f914edcc2e Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 8 Mar 2024 22:36:16 +0800 Subject: [PATCH] by Robin at 20240308 --- app/mix/service/utilservice.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 950a77f2..0ce3ec41 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -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