From 4c230b4c1e56ee63b06c46eb41f3327449711d17 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 20 Nov 2023 10:56:28 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E6=B8=85=E7=90=86=E7=A7=8D=E5=AD=90=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 2 +- app/chain/torrents.py | 9 +++++++++ app/modules/douban/__init__.py | 2 ++ app/modules/themoviedb/__init__.py | 2 ++ app/scheduler.py | 11 ++++++++++- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 0bf69e1c..a650a82a 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -192,7 +192,7 @@ class DownloadChain(ChainBase): channel=channel, userid=userid) if not content: - return + return None else: content = torrent_file # 获取种子文件的文件夹名和文件清单 diff --git a/app/chain/torrents.py b/app/chain/torrents.py index 0b914cfc..3af74851 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -60,6 +60,15 @@ class TorrentsChain(ChainBase, metaclass=Singleton): else: return self.load_cache(self._rss_file) or {} + def clear_torrents(self): + """ + 清理种子缓存数据 + """ + logger.info(f'开始清理种子缓存数据 ...') + self.remove_cache(self._spider_file) + self.remove_cache(self._rss_file) + logger.info(f'种子缓存数据清理完成') + @cached(cache=TTLCache(maxsize=128, ttl=595)) def browse(self, domain: str) -> List[TorrentInfo]: """ diff --git a/app/modules/douban/__init__.py b/app/modules/douban/__init__.py index f7dc9aee..91b4af46 100644 --- a/app/modules/douban/__init__.py +++ b/app/modules/douban/__init__.py @@ -705,8 +705,10 @@ class DoubanModule(_ModuleBase): """ 清除缓存 """ + logger.info("开始清除豆瓣缓存 ...") self.doubanapi.clear_cache() self.cache.clear() + logger.info("豆瓣缓存清除完成") def douban_movie_credits(self, doubanid: str, page: int = 1, count: int = 20) -> List[dict]: """ diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 1ddc666d..3d49526d 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -447,5 +447,7 @@ class TheMovieDbModule(_ModuleBase): """ 清除缓存 """ + logger.info("开始清除TMDB缓存 ...") self.tmdb.clear_cache() self.cache.clear() + logger.info("TMDB缓存清除完成") diff --git a/app/scheduler.py b/app/scheduler.py index 510dba51..656438c0 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -13,6 +13,7 @@ from app.chain.cookiecloud import CookieCloudChain from app.chain.mediaserver import MediaServerChain from app.chain.subscribe import SubscribeChain from app.chain.tmdb import TmdbChain +from app.chain.torrents import TorrentsChain from app.chain.transfer import TransferChain from app.core.config import settings from app.log import logger @@ -43,6 +44,14 @@ class Scheduler(metaclass=Singleton): _event = threading.Event() def __init__(self): + + def clear_cache(): + """ + 清理缓存 + """ + TorrentsChain().clear_cache() + SchedulerChain().clear_cache() + # 各服务的运行状态 self._jobs = { "cookiecloud": { @@ -73,7 +82,7 @@ class Scheduler(metaclass=Singleton): "running": False, }, "clear_cache": { - "func": SchedulerChain().clear_cache, + "func": clear_cache, "running": False, } }