media_cache.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package ugc
  2. import (
  3. "encoding/json"
  4. appDao "go-common/app/job/main/tv/dao/app"
  5. ugcmdl "go-common/app/job/main/tv/model/ugc"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. // arcDatabus refreshes the mc cache for archive media info
  10. func (s *Service) arcDatabus(jsonstr json.RawMessage) (err error) {
  11. var (
  12. arc = &ugcmdl.DatabusArc{}
  13. pubtime int64
  14. )
  15. if err = json.Unmarshal(jsonstr, arc); err != nil {
  16. log.Error("json.Unmarshal(%s) error(%v)", jsonstr, err)
  17. return
  18. }
  19. arcMark := arc.New
  20. if pubtime, err = appDao.TimeTrans(arcMark.Pubtime); err != nil {
  21. log.Warn("arcDatabus Pubtime AVID: %d, Err %v", arcMark.AID, err)
  22. }
  23. // we prepare the cms cache
  24. if err = s.dao.SetArcCMS(ctx, &ugcmdl.ArcCMS{
  25. // Media Info
  26. Title: arcMark.Title,
  27. AID: arcMark.AID,
  28. Content: arcMark.Content,
  29. Cover: arcMark.Cover,
  30. TypeID: arcMark.TypeID,
  31. Pubtime: xtime.Time(pubtime),
  32. Videos: arcMark.Videos,
  33. Valid: arcMark.Valid,
  34. Deleted: arcMark.Deleted,
  35. Result: arcMark.Result,
  36. }); err != nil {
  37. log.Error("arcDatabus setArcCMS AVID: %d, Err %v", arcMark.AID, err)
  38. }
  39. // we prepare the rpc cache for the ugc view page if the archive is able to play
  40. if arcMark.IsPass() {
  41. s.viewCache(int64(arcMark.AID))
  42. appDao.PromInfo("ArcRPC-AddCache")
  43. }
  44. s.listMtn(arc.Old, arc.New)
  45. return
  46. }
  47. // videoDatabus refreshes the mc cache for video media info
  48. func (s *Service) videoDatabus(jsonstr json.RawMessage) (err error) {
  49. var (
  50. video = &ugcmdl.DatabusVideo{}
  51. criCID = s.c.UgcSync.Cfg.CriticalCid
  52. )
  53. if err = json.Unmarshal(jsonstr, video); err != nil {
  54. log.Error("json.Unmarshal(%s) error(%v)", jsonstr, err)
  55. return
  56. }
  57. vm := video.New
  58. if vm.ToReport(criCID) { // if the video has not been reported yet, we do it and update the mark field from 0 to 1
  59. s.repCidCh <- vm.CID
  60. }
  61. if vm.ToAudit(criCID) {
  62. log.Info("videoDatabus addAudCid cAid %d", vm.AID)
  63. s.audAidCh <- []int64{vm.AID} // add aid into channel to treat
  64. }
  65. if video.Old == nil { // if the brand new episode can play
  66. if vm.CanPlay() {
  67. log.Info("videoDatabus reshelfAid cAid %d", vm.AID)
  68. s.reshelfAidCh <- vm.AID
  69. }
  70. } else { // or it couldn't play and it passes now
  71. if !video.Old.CanPlay() && vm.CanPlay() {
  72. log.Info("videoDatabus reshelfAid cAid %d", vm.AID)
  73. s.reshelfAidCh <- vm.AID
  74. }
  75. }
  76. if err = s.dao.SetVideoCMS(ctx, vm.ToCMS()); err != nil { // we prepare the cms cache
  77. log.Warn("videoDatabus setVideoCMS CID: %d, Err %v", vm.CID, err)
  78. }
  79. return
  80. }