zone_index.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package pgc
  2. import (
  3. "context"
  4. model "go-common/app/job/main/tv/model/pgc"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _seasonPassed = 1
  9. _epPassed = 3
  10. _cmsValid = 1
  11. _notDeleted = 0
  12. )
  13. // ZoneIdx finds out all the passed seasons in DB and then arrange them in a sorted set in Redis
  14. func (s *Service) ZoneIdx() {
  15. var (
  16. _pgcZones = s.c.Cfg.PGCZonesID
  17. ctx = context.Background()
  18. )
  19. for _, v := range _pgcZones {
  20. zoneSns, err := s.dao.PassedSn(ctx, v)
  21. if err != nil {
  22. log.Error("ZoneIdx - PassedSn %d Error %v", v, err)
  23. continue
  24. }
  25. if err = s.dao.Flush(ctx, v, zoneSns); err != nil {
  26. log.Error("ZoneIdx - Flush %d Error %v", v, err)
  27. continue
  28. }
  29. }
  30. }
  31. // listMtn maintains the list of zone index
  32. func (s *Service) listMtn(oldSn *model.MediaSn, newSn *model.MediaSn) (err error) {
  33. if oldSn == nil {
  34. log.Info("ListMtn OldSn is Nil, NewSn is %v", newSn)
  35. oldSn = &model.MediaSn{}
  36. }
  37. if oldSn.Check == _seasonPassed && oldSn.IsDeleted == _notDeleted && oldSn.Valid == _cmsValid { // previously passed
  38. if !(newSn.Check == _seasonPassed && newSn.IsDeleted == _notDeleted && newSn.Valid == _cmsValid) { // not passed now
  39. if err = s.dao.ZRemIdx(ctx, newSn.Category, newSn.ID); err != nil {
  40. log.Error("listMtn - ZRemIdx - Category: %d, Sn: %s, Error: %v", newSn.Category, newSn, err)
  41. return
  42. }
  43. log.Info("Remove Sid %d From Zone %d", newSn.ID, newSn.Category)
  44. }
  45. } else { // previously not passed, or not exist
  46. if newSn.Check == _seasonPassed && newSn.IsDeleted == _notDeleted && newSn.Valid == _cmsValid { // passed now
  47. if err = s.dao.ZAddIdx(ctx, newSn.Category, newSn.Ctime, newSn.ID); err != nil {
  48. log.Error("listMtn - ZAddIdx - Category: %d, Sn: %s, Error: %v", newSn.Category, newSn, err)
  49. return
  50. }
  51. log.Info("Add Sid %d Into Zone %d", newSn.ID, newSn.Category)
  52. }
  53. }
  54. return
  55. }