fix torrent

This commit is contained in:
jxxghp
2025-08-23 18:10:33 +08:00
parent e90359eb08
commit 31f342fe4f
2 changed files with 6 additions and 10 deletions
+3 -8
View File
@@ -1130,7 +1130,7 @@ class TTLCache(CacheProxy):
使用项目的缓存后端实现,支持 Redis 和内存缓存 使用项目的缓存后端实现,支持 Redis 和内存缓存
""" """
def __init__(self, maxsize: int = 128, ttl: int = 600, region: Optional[str] = None): def __init__(self, maxsize: int = 1024, ttl: int = 600, region: Optional[str] = None):
""" """
初始化 TTL 缓存 初始化 TTL 缓存
@@ -1138,10 +1138,7 @@ class TTLCache(CacheProxy):
:param ttl: 缓存的存活时间,单位秒 :param ttl: 缓存的存活时间,单位秒
:param region: 缓存的区,为 None 时使用默认区 :param region: 缓存的区,为 None 时使用默认区
""" """
self.maxsize = maxsize super().__init__(Cache(maxsize=maxsize, ttl=ttl), region or DEFAULT_CACHE_REGION, ttl)
self.ttl = ttl
cache_backend = Cache(maxsize=maxsize, ttl=ttl)
super().__init__(cache_backend, region or DEFAULT_CACHE_REGION, ttl)
class LRUCache(CacheProxy): class LRUCache(CacheProxy):
@@ -1157,6 +1154,4 @@ class LRUCache(CacheProxy):
:param maxsize: 缓存的最大条目数 :param maxsize: 缓存的最大条目数
:param region: 缓存的区,为 None 时使用默认区 :param region: 缓存的区,为 None 时使用默认区
""" """
self.maxsize = maxsize super().__init__(Cache(maxsize=maxsize), region or DEFAULT_CACHE_REGION)
cache_backend = Cache(maxsize=maxsize)
super().__init__(cache_backend, region or DEFAULT_CACHE_REGION)
+3 -2
View File
@@ -7,6 +7,7 @@ from urllib.parse import unquote
from torrentool.api import Torrent from torrentool.api import Torrent
from app.core.cache import FileCache from app.core.cache import FileCache
from app.core.cache import TTLCache
from app.core.config import settings from app.core.config import settings
from app.core.context import Context, TorrentInfo, MediaInfo from app.core.context import Context, TorrentInfo, MediaInfo
from app.core.meta import MetaBase from app.core.meta import MetaBase
@@ -25,7 +26,7 @@ class TorrentHelper:
""" """
def __init__(self): def __init__(self):
self._invalid_torrents = [] self._invalid_torrents = TTLCache(maxsize=128, ttl=3600 * 24)
def download_torrent(self, url: str, def download_torrent(self, url: str,
cookie: Optional[str] = None, cookie: Optional[str] = None,
@@ -351,7 +352,7 @@ class TorrentHelper:
添加无效种子 添加无效种子
""" """
if url not in self._invalid_torrents: if url not in self._invalid_torrents:
self._invalid_torrents.append(url) self._invalid_torrents[url] = True
@staticmethod @staticmethod
def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaBase, torrent: TorrentInfo) -> bool: def match_torrent(mediainfo: MediaInfo, torrent_meta: MetaBase, torrent: TorrentInfo) -> bool: