Skip to content

Commit

Permalink
增加大内存模式
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jul 21, 2023
1 parent 37a1222 commit 89a9bba
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ docker pull jxxghp/moviepilot:latest

### 2. **进阶配置**

- **BIG_MEMORY_MODE:** 大内存模式,默认为`false`,开启后会占用更多的内存,但响应速度会更快

- **MOVIE_RENAME_FORMAT:** 电影重命名格式

`MOVIE_RENAME_FORMAT`支持的配置项:
Expand Down
2 changes: 1 addition & 1 deletion app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def refresh(self):
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")} 获取到种子')
Expand Down
20 changes: 20 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -179,6 +181,24 @@ def PLUGIN_DATA_PATH(self):
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:
Expand Down
3 changes: 2 additions & 1 deletion app/modules/douban/apiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import requests

from app.core.config import settings
from app.utils.http import RequestUtils
from app.utils.singleton import Singleton

Expand Down Expand Up @@ -158,7 +159,7 @@ def __sign(cls, url: str, ts: int, method='GET') -> str:
).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

Expand Down
2 changes: 1 addition & 1 deletion app/modules/fanart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __name(fanart_name: str) -> str:
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
Expand Down
4 changes: 2 additions & 2 deletions app/modules/themoviedb/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):
# 开启缓存
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
# 语种
Expand Down Expand Up @@ -452,7 +452,7 @@ def match_multi(self, name: str) -> Optional[dict]:
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网站,直接抓取结果,结果只有一条时才返回
Expand Down
2 changes: 2 additions & 0 deletions app/modules/themoviedb/tmdb_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 89a9bba

Please sign in to comment.