sky_horse.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package v2
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. v2pb "go-common/app/interface/live/app-interface/api/http/v2"
  6. "go-common/app/interface/live/app-interface/dao"
  7. "go-common/library/ecode"
  8. )
  9. const (
  10. _skyHorseRecTimeOut = 100
  11. _recTypeForce = 3
  12. _mobileIndexBadgeColorDefault = "#FB9E60"
  13. _recTypeSkyHorse = 4
  14. )
  15. func (s *IndexService) getSkyHorseRoomListForIndex(ctx context.Context, respMyIdol *v2pb.MMyIdol, mid int64, buvid string, build int64, platform string, recPage int64, quality int64) (respSkyHorseRoomList []*v2pb.CommonRoomItem, err error) {
  16. respSkyHorseRoomList = make([]*v2pb.CommonRoomItem, 0)
  17. duplicate := make([]int64, 0)
  18. // ctx可以换带cancel或timeout的
  19. for _, idol := range respMyIdol.List {
  20. duplicate = append(duplicate, idol.Roomid)
  21. }
  22. respSkyHorseRoomList, err = s.getSkyHorseRoomList(ctx, mid, buvid, build, platform, duplicate, recPage, quality)
  23. if err != nil {
  24. return
  25. }
  26. return
  27. }
  28. func (s *IndexService) getSkyHorseRoomList(ctx context.Context, uid int64, buvid string, build int64, platform string, idolIds []int64, recPage int64, quality int64) (respSkyHorseRoomList []*v2pb.CommonRoomItem, err error) {
  29. // 天马对关注去重
  30. duplicates := idolIds
  31. idolDuplicateMap := make(map[int64]bool)
  32. for _, id := range duplicates {
  33. if _, ok := idolDuplicateMap[id]; !ok {
  34. idolDuplicateMap[id] = true
  35. }
  36. }
  37. strongRecLen := 0
  38. //天马不考虑位置好的
  39. recPool := s.getRecPoolAllPosition(ctx, nil, duplicates)
  40. // 获取强推
  41. if len(recPool) > 0 {
  42. for _, strongInfo := range recPool {
  43. if strongInfo.Roomid == 0 {
  44. continue
  45. }
  46. if _, ok := idolDuplicateMap[strongInfo.Roomid]; !ok {
  47. duplicates = append(duplicates, strongInfo.Roomid)
  48. strongRecLen++
  49. }
  50. }
  51. }
  52. skyHorseRec, skyHorseErr := dao.SkyHorseApi.GetSkyHorseRec(ctx, uid, buvid, build, platform, duplicates, strongRecLen, _skyHorseRecTimeOut)
  53. if skyHorseErr != nil {
  54. err = errors.WithMessage(ecode.SkyHorseError, "")
  55. return
  56. }
  57. roomIds := make([]int64, 0)
  58. for _, skyHorseInfo := range skyHorseRec.Data {
  59. roomIds = append(roomIds, int64(skyHorseInfo.Id))
  60. }
  61. return s.getRecRoomList(ctx, roomIds, recPool, build, platform, idolDuplicateMap, _recTypeSkyHorse, quality)
  62. }