From 89a9bba90978f44d08cc07948d4d346521ff302c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 21 Jul 2023 23:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=A7=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ app/chain/subscribe.py | 2 +- app/core/config.py | 20 ++++++++++++++++++++ app/modules/douban/apiv2.py | 3 ++- app/modules/fanart/__init__.py | 2 +- app/modules/themoviedb/tmdb.py | 4 ++-- app/modules/themoviedb/tmdb_cache.py | 2 ++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 45109ddd..5ff15668 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,8 @@ docker pull jxxghp/moviepilot:latest ### 2. **进阶配置** +- **BIG_MEMORY_MODE:** 大内存模式,默认为`false`,开启后会占用更多的内存,但响应速度会更快 + - **MOVIE_RENAME_FORMAT:** 电影重命名格式 `MOVIE_RENAME_FORMAT`支持的配置项: diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 40cd771d..f41bf308 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -361,7 +361,7 @@ class SubscribeChain(ChainBase): else: torrents_cache[domain].append(context) # 如果超过了200条则移除最早的一条 - if len(torrents_cache[domain]) > 200: + if len(torrents_cache[domain]) > settings.CACHE_CONF.get('torrents'): torrents_cache[domain].pop(0) else: logger.info(f'{indexer.get("name")} 获取到种子') diff --git a/app/core/config.py b/app/core/config.py index 1dd69075..9ba6285d 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -152,6 +152,8 @@ class Settings(BaseSettings): "/Season {{season}}" \ "/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}" \ "{{fileExt}}" + # 大内存模式 + BIG_MEMORY_MODE: bool = False @property def INNER_CONFIG_PATH(self): @@ -179,6 +181,24 @@ class Settings(BaseSettings): def LOG_PATH(self): return self.CONFIG_PATH / "logs" + @property + def CACHE_CONF(self): + if self.BIG_MEMORY_MODE: + return { + "tmdb": 1024, + "torrents": 200, + "douban": 512, + "fanart": 512, + "meta": 15 * 24 * 3600 + } + return { + "tmdb": 256, + "torrents": 100, + "douban": 256, + "fanart": 128, + "meta": 7 * 24 * 3600 + } + @property def PROXY(self): if self.PROXY_HOST: diff --git a/app/modules/douban/apiv2.py b/app/modules/douban/apiv2.py index c30a245e..eacb3d10 100644 --- a/app/modules/douban/apiv2.py +++ b/app/modules/douban/apiv2.py @@ -9,6 +9,7 @@ from urllib import parse import requests +from app.core.config import settings from app.utils.http import RequestUtils from app.utils.singleton import Singleton @@ -158,7 +159,7 @@ class DoubanApi(metaclass=Singleton): ).decode() @classmethod - @lru_cache(maxsize=256) + @lru_cache(maxsize=settings.CACHE_CONF.get('douban')) def __invoke(cls, url, **kwargs): req_url = cls._base_url + url diff --git a/app/modules/fanart/__init__.py b/app/modules/fanart/__init__.py index 5d07bb3c..2b2f9109 100644 --- a/app/modules/fanart/__init__.py +++ b/app/modules/fanart/__init__.py @@ -62,7 +62,7 @@ class FanartModule(_ModuleBase): return result @classmethod - @lru_cache(maxsize=256) + @lru_cache(maxsize=settings.CACHE_CONF.get('fanart')) def __request_fanart(cls, media_type: MediaType, queryid: Union[str, int]) -> Optional[dict]: if media_type == MediaType.MOVIE: image_url = cls._movie_url % queryid diff --git a/app/modules/themoviedb/tmdb.py b/app/modules/themoviedb/tmdb.py index 844b5646..e24fd8cc 100644 --- a/app/modules/themoviedb/tmdb.py +++ b/app/modules/themoviedb/tmdb.py @@ -33,7 +33,7 @@ class TmdbHelper: # 开启缓存 self.tmdb.cache = True # 缓存大小 - self.tmdb.REQUEST_CACHE_MAXSIZE = 256 + self.tmdb.REQUEST_CACHE_MAXSIZE = settings.CACHE_CONF.get('tmdb') # APIKEY self.tmdb.api_key = settings.TMDB_API_KEY # 语种 @@ -452,7 +452,7 @@ class TmdbHelper: return multi return {} - @lru_cache(maxsize=128) + @lru_cache(maxsize=settings.CACHE_CONF.get('tmdb')) def match_web(self, name: str, mtype: MediaType) -> Optional[dict]: """ 搜索TMDB网站,直接抓取结果,结果只有一条时才返回 diff --git a/app/modules/themoviedb/tmdb_cache.py b/app/modules/themoviedb/tmdb_cache.py index facf7f39..d27fb019 100644 --- a/app/modules/themoviedb/tmdb_cache.py +++ b/app/modules/themoviedb/tmdb_cache.py @@ -33,8 +33,10 @@ class TmdbCache(metaclass=Singleton): _tmdb_cache_expire: bool = True def __init__(self): + global EXPIRE_TIMESTAMP self._meta_path = settings.TEMP_PATH / "__tmdb_cache__" self._meta_data = self.__load(self._meta_path) + EXPIRE_TIMESTAMP = settings.CACHE_CONF.get('meta') def clear(self): """