feat: cache download status number

This commit is contained in:
Simon Ding
2024-12-11 20:04:37 +08:00
parent 7c05acd1cf
commit 1020190c01
2 changed files with 28 additions and 16 deletions

View File

@@ -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