list_mc.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/openplatform/article/model"
  6. )
  7. func listArtsKey(id int64) string {
  8. return fmt.Sprintf("art_rl1_arts_%d", id)
  9. }
  10. func listKey(id int64) string {
  11. return fmt.Sprintf("art_rll_%d", id)
  12. }
  13. func articleListKey(aid int64) string {
  14. return fmt.Sprintf("art_rlal_%d", aid)
  15. }
  16. func upListsKey(mid int64) string {
  17. return fmt.Sprintf("art_uplists_%d", mid)
  18. }
  19. func listReadCountKey(id int64) string {
  20. return fmt.Sprintf("art_lrc_%d", id)
  21. }
  22. func slideArticlesKey(buvid string) string {
  23. return fmt.Sprintf("art_slidelists_%s", buvid)
  24. }
  25. // ListArtsCacheMap get read list articles cache
  26. func (d *Dao) ListArtsCacheMap(c context.Context, id int64) (res map[int64]*model.ListArtMeta, err error) {
  27. var arts []*model.ListArtMeta
  28. if arts, err = d.CacheListArts(c, id); err != nil {
  29. return
  30. }
  31. for _, art := range arts {
  32. if res == nil {
  33. res = make(map[int64]*model.ListArtMeta)
  34. }
  35. res[art.ID] = art
  36. }
  37. return
  38. }
  39. // SetArticleListCache set article list cache
  40. func (d *Dao) SetArticleListCache(c context.Context, listID int64, arts []*model.ListArtMeta) (err error) {
  41. if len(arts) == 0 {
  42. return
  43. }
  44. m := make(map[int64]int64)
  45. for _, art := range arts {
  46. m[art.ID] = listID
  47. }
  48. err = d.SetArticlesListCache(c, m)
  49. return
  50. }