From cdbe5b2e2f250415a0eb2b45a478032be51bc168 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 21 Oct 2023 08:17:10 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=8A=A0=E5=A4=A7=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20&&=20=E8=AE=A2=E9=98=85=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=BC=91=E7=9C=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/search.py | 3 ++- app/chain/subscribe.py | 7 +++++++ app/chain/torrents.py | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/chain/search.py b/app/chain/search.py index 301e2ecc..9d61a1ba 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -16,10 +16,11 @@ from app.helper.torrent import TorrentHelper from app.log import logger from app.schemas import NotExistMediaInfo from app.schemas.types import MediaType, ProgressKey, SystemConfigKey +from app.utils.singleton import Singleton from app.utils.string import StringUtils -class SearchChain(ChainBase): +class SearchChain(ChainBase, metaclass=Singleton): """ 站点资源搜索处理链 """ diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 6c0b9ea0..95722ee2 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -1,5 +1,7 @@ import json +import random import re +import time from datetime import datetime from typing import Dict, List, Optional, Union, Tuple @@ -162,6 +164,11 @@ class SubscribeChain(ChainBase): if (now - subscribe_time).total_seconds() < 60: logger.debug(f"订阅标题:{subscribe.name} 新增小于1分钟,暂不搜索...") continue + # 随机休眠1-5分钟 + if not sid and state == 'R': + sleep_time = random.randint(60, 300) + logger.info(f'订阅搜索随机休眠 {sleep_time} 秒 ...') + time.sleep(sleep_time) logger.info(f'开始搜索订阅,标题:{subscribe.name} ...') # 如果状态为N则更新为R if subscribe.state == 'N': diff --git a/app/chain/torrents.py b/app/chain/torrents.py index 636c4fb9..142076bf 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -58,7 +58,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton): else: return self.load_cache(self._rss_file) or {} - @cached(cache=TTLCache(maxsize=128 if settings.BIG_MEMORY_MODE else 1, ttl=600)) + @cached(cache=TTLCache(maxsize=128, ttl=600)) def browse(self, domain: str) -> List[TorrentInfo]: """ 浏览站点首页内容,返回种子清单,TTL缓存10分钟 @@ -71,7 +71,7 @@ class TorrentsChain(ChainBase, metaclass=Singleton): return [] return self.refresh_torrents(site=site) - @cached(cache=TTLCache(maxsize=128 if settings.BIG_MEMORY_MODE else 1, ttl=300)) + @cached(cache=TTLCache(maxsize=128, ttl=300)) def rss(self, domain: str) -> List[TorrentInfo]: """ 获取站点RSS内容,返回种子清单,TTL缓存5分钟