service.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package account
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/creative/conf"
  6. "go-common/app/interface/main/creative/dao/account"
  7. "go-common/app/interface/main/creative/dao/archive"
  8. "go-common/app/interface/main/creative/dao/article"
  9. "go-common/app/interface/main/creative/dao/up"
  10. "go-common/app/interface/main/creative/service"
  11. "go-common/library/log"
  12. "go-common/library/stat/prom"
  13. )
  14. //Service struct.
  15. type Service struct {
  16. c *conf.Config
  17. acc *account.Dao
  18. article *article.Dao
  19. archive *archive.Dao
  20. up *up.Dao
  21. exemptIDCheckUps map[int64]int64
  22. exemptZeroLevelAndAnswerUps map[int64]int64
  23. uploadTopSizeUps map[int64]int64
  24. missch chan func()
  25. pCacheHit *prom.Prom
  26. pCacheMiss *prom.Prom
  27. }
  28. //New get service.
  29. func New(c *conf.Config, rpcdaos *service.RPCDaos) *Service {
  30. s := &Service{
  31. c: c,
  32. acc: rpcdaos.Acc,
  33. article: rpcdaos.Art,
  34. archive: rpcdaos.Arc,
  35. up: rpcdaos.Up,
  36. missch: make(chan func(), 1024),
  37. pCacheHit: prom.CacheHit,
  38. pCacheMiss: prom.CacheMiss,
  39. }
  40. s.loadExemptIDCheckUps()
  41. s.loadExemptZeroLevelAndAnswer()
  42. s.loadUpSpecialUploadTopSize()
  43. go s.loadproc()
  44. go s.cacheproc()
  45. return s
  46. }
  47. // loadproc
  48. func (s *Service) loadproc() {
  49. for {
  50. time.Sleep(5 * time.Minute)
  51. s.loadExemptIDCheckUps()
  52. s.loadExemptZeroLevelAndAnswer()
  53. s.loadUpSpecialUploadTopSize()
  54. }
  55. }
  56. // loadExemptIDCheckUps 白名单人员,免实名认证 type=8.
  57. func (s *Service) loadExemptIDCheckUps() {
  58. ups, err := s.up.UpSpecial(context.TODO(), 8)
  59. if err != nil {
  60. return
  61. }
  62. s.exemptIDCheckUps = ups
  63. log.Info("exemptIDCheckUps ups: (%v)", len(ups))
  64. }
  65. // loadExemptIDCheckUps 白名单人员,免账号激活,免账号升级到1级 type=12
  66. func (s *Service) loadExemptZeroLevelAndAnswer() {
  67. ups, err := s.up.UpSpecial(context.TODO(), 12)
  68. if err != nil {
  69. return
  70. }
  71. s.exemptZeroLevelAndAnswerUps = ups
  72. }
  73. // loadUpSpecialUploadTopSize 投稿名单限制升级 上传视频可以超过4G,但是在8G以下 type=16
  74. func (s *Service) loadUpSpecialUploadTopSize() {
  75. ups, err := s.up.UpSpecial(context.TODO(), 16)
  76. if err != nil {
  77. return
  78. }
  79. s.uploadTopSizeUps = ups
  80. }
  81. // AddCache add to chan for cache
  82. func (s *Service) addCache(f func()) {
  83. select {
  84. case s.missch <- f:
  85. default:
  86. log.Warn("cacheproc chan full")
  87. }
  88. }
  89. // cacheproc is a routine for execute closure.
  90. func (s *Service) cacheproc() {
  91. for {
  92. f := <-s.missch
  93. f()
  94. }
  95. }