From 0f917701969050474d2eb1a4822f7fb5218e9ac4 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 4 Aug 2023 17:22:41 +0800 Subject: [PATCH] fix cache --- app/chain/subscribe.py | 8 ++++++-- app/core/config.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 7ee146e1..9c02cd0d 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -367,6 +367,10 @@ class SubscribeChain(ChainBase): logger.info(f'开始刷新 {indexer.get("name")} 最新种子 ...') domain = StringUtils.get_url_domain(indexer.get("domain")) torrents: List[TorrentInfo] = self.refresh_torrents(site=indexer) + # 按pubdate降序排列 + torrents.sort(key=lambda x: x.pubdate, reverse=True) + # 取前N条 + torrents = torrents[:settings.CACHE_CONF.get('refresh')] if torrents: # 过滤出没有处理过的种子 torrents = [torrent for torrent in torrents @@ -397,9 +401,9 @@ class SubscribeChain(ChainBase): torrents_cache[domain] = [context] else: torrents_cache[domain].append(context) - # 如果超过了200条则移除最早的一条 + # 如果超过了限制条数则移除掉前面的 if len(torrents_cache[domain]) > settings.CACHE_CONF.get('torrents'): - torrents_cache[domain].pop(0) + torrents_cache[domain] = torrents_cache[domain][-settings.CACHE_CONF.get('torrents'):] # 回收资源 del torrents else: diff --git a/app/core/config.py b/app/core/config.py index 716523b2..1fa442be 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -194,14 +194,16 @@ class Settings(BaseSettings): if self.BIG_MEMORY_MODE: return { "tmdb": 1024, - "torrents": 200, + "refresh": 50, + "torrents": 100, "douban": 512, "fanart": 512, "meta": 15 * 24 * 3600 } return { "tmdb": 256, - "torrents": 100, + "refresh": 30, + "torrents": 50, "douban": 256, "fanart": 128, "meta": 7 * 24 * 3600