mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
feat: cache download status number
This commit is contained in:
@@ -7,9 +7,11 @@ import (
|
||||
"net/url"
|
||||
"polaris/db"
|
||||
"polaris/log"
|
||||
"polaris/pkg/cache"
|
||||
"polaris/pkg/tmdb"
|
||||
"polaris/server/core"
|
||||
"polaris/ui"
|
||||
"time"
|
||||
|
||||
ginzap "github.com/gin-contrib/zap"
|
||||
|
||||
@@ -22,20 +24,24 @@ import (
|
||||
func NewServer(db *db.Client) *Server {
|
||||
r := gin.Default()
|
||||
s := &Server{
|
||||
r: r,
|
||||
db: db,
|
||||
language: db.GetLanguage(),
|
||||
r: r,
|
||||
db: db,
|
||||
language: db.GetLanguage(),
|
||||
monitorNumCache: cache.NewCache[int, int](10 * time.Minute),
|
||||
downloadNumCache: cache.NewCache[int, int](10 * time.Minute),
|
||||
}
|
||||
s.core = core.NewClient(db, s.language)
|
||||
return s
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
r *gin.Engine
|
||||
db *db.Client
|
||||
core *core.Client
|
||||
language string
|
||||
jwtSerect string
|
||||
r *gin.Engine
|
||||
db *db.Client
|
||||
core *core.Client
|
||||
language string
|
||||
jwtSerect string
|
||||
monitorNumCache *cache.Cache[int, int]
|
||||
downloadNumCache *cache.Cache[int, int]
|
||||
}
|
||||
|
||||
func (s *Server) Serve() error {
|
||||
|
||||
@@ -102,17 +102,23 @@ func (s *Server) GetTvWatchlist(c *gin.Context) (interface{}, error) {
|
||||
MonitoredNum: 0,
|
||||
DownloadedNum: 0,
|
||||
}
|
||||
|
||||
details := s.db.GetMediaDetails(item.ID)
|
||||
|
||||
for _, ep := range details.Episodes {
|
||||
if ep.Monitored {
|
||||
ms.MonitoredNum++
|
||||
if ep.Status == episode.StatusDownloaded {
|
||||
ms.DownloadedNum++
|
||||
mon, ok1 := s.monitorNumCache.Get(item.ID)
|
||||
dow, ok2 := s.downloadNumCache.Get(item.ID)
|
||||
if ok1 && ok2 {
|
||||
ms.MonitoredNum = mon
|
||||
ms.DownloadedNum = dow
|
||||
} else {
|
||||
details := s.db.GetMediaDetails(item.ID)
|
||||
for _, ep := range details.Episodes {
|
||||
if ep.Monitored {
|
||||
ms.MonitoredNum++
|
||||
if ep.Status == episode.StatusDownloaded {
|
||||
ms.DownloadedNum++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res[i] = ms
|
||||
}
|
||||
return res, nil
|
||||
|
||||
Reference in New Issue
Block a user