live_rec.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package v2
  2. import (
  3. "context"
  4. v2pb "go-common/app/interface/live/app-interface/api/http/v2"
  5. recommendV1 "go-common/app/service/live/recommend/api/grpc/v1"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _recTypeRecommend = 5
  10. _recNum = 6 //获取推荐的数量
  11. )
  12. func (s *IndexService) getLiveRecRoomList(ctx context.Context, respMyIdol *v2pb.MMyIdol, mid int64, build int64, platform string, recPage int64, quality int64) (respLiuGangRecRoomList []*v2pb.CommonRoomItem, err error) {
  13. duplicate := make([]int64, 0)
  14. // ctx可以换带cancel或timeout的
  15. for _, idol := range respMyIdol.List {
  16. duplicate = append(duplicate, idol.Roomid)
  17. }
  18. return s.getRecInfo(ctx, mid, duplicate, build, platform, recPage, quality)
  19. }
  20. func (s *IndexService) getLiveRecRoomListForChange(ctx context.Context, mid int64, build int64, platform string, duplicate []int64, recPage int64, quality int64) (respLiuGangRecRoomList []*v2pb.CommonRoomItem, err error) {
  21. return s.getRecInfo(ctx, mid, duplicate, build, platform, recPage, quality)
  22. }
  23. func (s *IndexService) getRecInfo(ctx context.Context, mid int64, duplicate []int64, build int64, platform string, recPage int64, quality int64) (respLiveRecRoomList []*v2pb.CommonRoomItem, err error) {
  24. // 天马对关注去重
  25. duplicates := duplicate
  26. idolDuplicateMap := make(map[int64]bool)
  27. for _, id := range duplicates {
  28. if _, ok := idolDuplicateMap[id]; !ok {
  29. idolDuplicateMap[id] = true
  30. }
  31. }
  32. // 获取强推
  33. strongRecLen := 0
  34. //不考虑位置好的
  35. recPool := s.getRecPoolAllPosition(ctx, nil, duplicates)
  36. // 获取强推
  37. if len(recPool) > 0 {
  38. for _, strongInfo := range recPool {
  39. if strongInfo.Roomid == 0 {
  40. continue
  41. }
  42. if _, ok := idolDuplicateMap[strongInfo.Roomid]; !ok {
  43. duplicates = append(duplicates, strongInfo.Roomid)
  44. strongRecLen++
  45. }
  46. }
  47. }
  48. respLiveRecRoomList = make([]*v2pb.CommonRoomItem, 0)
  49. count := _recNum - strongRecLen
  50. if count <= 0 {
  51. count = _recNum
  52. }
  53. GetRandomRecResp, err := s.recommendConn.RandomRecsByUser(ctx, &recommendV1.GetRandomRecReq{
  54. Uid: mid,
  55. Count: uint32(count), // 首页6个推荐
  56. ExistIds: duplicates,
  57. })
  58. if err != nil {
  59. log.Error("[GetLiveRoomList]GetLiveRecResp err, err:%+v", err)
  60. return
  61. }
  62. if GetRandomRecResp == nil {
  63. log.Error("[GetLiveRoomList]GetLiveRecResp empty err")
  64. return
  65. }
  66. if len(GetRandomRecResp.RoomIds) < count {
  67. log.Info("[GetLiveRoomList]GetLiveRecResp not enough num:%d,mid:%d", len(GetRandomRecResp.RoomIds), mid)
  68. return
  69. }
  70. respLiveRecRoomList, err = s.getRecRoomList(ctx, GetRandomRecResp.RoomIds, recPool, build, platform, idolDuplicateMap, _recTypeRecommend, quality)
  71. if err != nil {
  72. log.Error("[GetLiveRoomList]FillLiveRecRoomList err:%+v", err)
  73. }
  74. return
  75. }