zone_index.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package ugc
  2. import (
  3. "context"
  4. "go-common/app/job/main/tv/model/ugc"
  5. "go-common/library/log"
  6. )
  7. // ZoneIdx finds out all the passed seasons in DB and then arrange them in a sorted set in Redis
  8. func (s *Service) ZoneIdx() {
  9. var ctx = context.TODO()
  10. for catID, rel := range s.ugcTypesRel {
  11. var (
  12. firstTid = rel.TID
  13. totalTids = []int64{}
  14. )
  15. for _, v := range s.arcTypes {
  16. if v.Pid == firstTid {
  17. totalTids = append(totalTids, int64(v.ID)) // add second level types
  18. }
  19. }
  20. totalTids = append(totalTids, int64(firstTid)) // add first level type
  21. IdxRanks, err := s.dao.PassedArcs(ctx, totalTids)
  22. if err != nil {
  23. log.Error("UgcZoneIdx - PassedArc TID %d Error %v", firstTid, err)
  24. continue
  25. }
  26. if err = s.appDao.Flush(ctx, int(catID), IdxRanks); err != nil {
  27. log.Error("UgcZoneIdx - Flush CatID %d Error %v", catID, err)
  28. continue
  29. }
  30. }
  31. }
  32. // loadTids loads the relation between typeIDs and category
  33. func (s *Service) loadTids() {
  34. var newTids = make(map[int32]int32)
  35. for catID, rel := range s.ugcTypesRel {
  36. firstTid := rel.TID
  37. for _, v := range s.arcTypes {
  38. if v.Pid == firstTid {
  39. newTids[v.ID] = catID
  40. }
  41. }
  42. newTids[firstTid] = catID
  43. }
  44. if len(newTids) > 0 {
  45. s.ugcTypesCat = newTids
  46. }
  47. }
  48. // listMtn maintains the list of zone index
  49. func (s *Service) listMtn(old *ugc.MarkArc, new *ugc.MarkArc) (err error) {
  50. if old == nil {
  51. log.Info("ListMtn Old is Nil, NewSn is %v", new)
  52. old = &ugc.MarkArc{}
  53. }
  54. if old.IsPass() && new.IsPass() && old.TypeID == new.TypeID { // no need to take action
  55. return
  56. }
  57. if !old.IsPass() && !new.IsPass() { // no need to take action
  58. return
  59. }
  60. if old.TypeID != 0 { // means old is not null
  61. if oldCat, ok := s.ugcTypesCat[old.TypeID]; ok { // if old one is in our list, remove it firstly
  62. if err = s.appDao.ZRemIdx(ctx, int(oldCat), old.AID); err != nil {
  63. log.Error("listMtn - ZRemIdx - Category: %d, Arc: %d, Error: %v", oldCat, old.AID, err)
  64. return
  65. }
  66. }
  67. }
  68. catID, ok := s.ugcTypesCat[new.TypeID]
  69. if !ok {
  70. log.Warn("TypeID %d Is Not our target, ignore", new.TypeID)
  71. return
  72. }
  73. if new.IsPass() { // passed now
  74. if err = s.appDao.ZAddIdx(ctx, int(catID), new.Ctime, new.AID); err != nil {
  75. log.Error("listMtn - ZAddIdx - Category: %d, Arc: %d, Error: %v", catID, new.AID, err)
  76. return
  77. }
  78. log.Info("Add Aid %d Into Zone %d", new.AID, catID)
  79. }
  80. return
  81. }