act.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package like
  2. import (
  3. "context"
  4. "sync/atomic"
  5. "time"
  6. "go-common/app/interface/main/activity/model/like"
  7. "go-common/library/log"
  8. )
  9. // RedDot get hot dot.
  10. func (s *Service) RedDot(c context.Context, mid int64) (redDot *like.RedDot, err error) {
  11. var lastTs int64
  12. redDot = new(like.RedDot)
  13. if mid <= 0 {
  14. return
  15. }
  16. if lastTime, e := s.dao.CacheRedDotTs(c, mid); e != nil {
  17. log.Error("s.dao.CacheRedDotTs mid(%d) error(%+v)", mid, e)
  18. } else {
  19. lastTs = lastTime
  20. }
  21. if s.newestSubTs > lastTs {
  22. redDot.RedDot = true
  23. }
  24. return
  25. }
  26. // ClearRetDot clear red dot.
  27. func (s *Service) ClearRetDot(c context.Context, mid int64) (err error) {
  28. if err = s.dao.AddCacheRedDotTs(c, mid, time.Now().Unix()); err != nil {
  29. log.Error("s.dao.AddCacheRedDotTs mid(%d) error(%+v)", mid, err)
  30. }
  31. return
  32. }
  33. func (s *Service) newestSubTsproc() {
  34. for {
  35. if like, err := s.dao.NewestSubject(context.Background(), like.VIDEOALL); err != nil || like == nil {
  36. log.Error("actNewTsproc s.dao.NewestSubject error(%+v)", err)
  37. time.Sleep(5 * time.Second)
  38. } else {
  39. newTs := like.Ctime.Time().Unix()
  40. if newTs > s.newestSubTs {
  41. atomic.StoreInt64(&s.newestSubTs, newTs)
  42. }
  43. }
  44. time.Sleep(time.Duration(s.c.Interval.NewestSubTsInterval))
  45. }
  46. }