From f484b64be39b272c128ef7d91d48d35461959052 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 6 Jun 2025 15:37:02 +0800 Subject: [PATCH] fix --- app/chain/__init__.py | 5 ----- app/chain/message.py | 10 ---------- app/chain/torrents.py | 23 +---------------------- 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 4cda6a46..d231c9aa 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -1,5 +1,4 @@ import copy -import gc import pickle import traceback from abc import ABCMeta @@ -69,10 +68,6 @@ class ChainBase(metaclass=ABCMeta): pickle.dump(cache, f) # noqa except Exception as err: logger.error(f"保存缓存 {filename} 出错:{str(err)}") - finally: - # 主动资源回收 - del cache - gc.collect() @staticmethod def remove_cache(filename: str) -> None: diff --git a/app/chain/message.py b/app/chain/message.py index 2824f3e7..4b497bd0 100644 --- a/app/chain/message.py +++ b/app/chain/message.py @@ -265,10 +265,6 @@ class MessageChain(ChainBase): userid=userid, total=len(contexts)) - # 清理内存 - del cache_list - del cache_data - elif cache_type in ["Subscribe", "ReSubscribe"]: # 订阅或洗版媒体 mediainfo: MediaInfo = cache_list[_choice] @@ -357,9 +353,6 @@ class MessageChain(ChainBase): items=cache_list[start:end], userid=userid, total=len(cache_list)) - # 清理内存 - del cache_list - del cache_data elif text.lower() == "n": # 下一页 @@ -396,9 +389,6 @@ class MessageChain(ChainBase): source=source, title=_current_meta.name, items=cache_list, userid=userid, total=total) - # 清理内存 - del cache_list - del cache_data else: # 搜索或订阅 diff --git a/app/chain/torrents.py b/app/chain/torrents.py index f2701d12..6877dead 100644 --- a/app/chain/torrents.py +++ b/app/chain/torrents.py @@ -1,4 +1,3 @@ -import gc import re import traceback from typing import Dict, List, Union, Optional @@ -10,7 +9,7 @@ from app.core.context import TorrentInfo, Context, MediaInfo from app.core.metainfo import MetaInfo from app.db.site_oper import SiteOper from app.db.systemconfig_oper import SystemConfigOper -from app.helper.memory import memory_optimized, clear_large_objects +from app.helper.memory import memory_optimized from app.helper.rss import RssHelper from app.helper.sites import SitesHelper from app.helper.torrent import TorrentHelper @@ -221,17 +220,7 @@ class TorrentsChain(ChainBase): torrents_cache[domain].append(context) # 如果超过了限制条数则移除掉前面的 if len(torrents_cache[domain]) > settings.CACHE_CONF["torrents"]: - # 优化:直接删除旧数据,无需重复清理(数据进缓存前已经clear过) - old_contexts = torrents_cache[domain][:-settings.CACHE_CONF["torrents"]] torrents_cache[domain] = torrents_cache[domain][-settings.CACHE_CONF["torrents"]:] - # 清理旧对象 - clear_large_objects(*old_contexts) - # 优化:清理不再需要的临时变量 - del meta, mediainfo, context - # 回收资源 - torrents.clear() - del torrents - gc.collect() else: logger.info(f'{indexer.get("name")} 没有获取到种子') @@ -243,17 +232,7 @@ class TorrentsChain(ChainBase): # 去除不在站点范围内的缓存种子 if sites and torrents_cache: - old_cache = torrents_cache torrents_cache = {k: v for k, v in torrents_cache.items() if k in domains} - # 清理不再使用的缓存数据(数据进缓存前已经clear过,无需重复清理) - removed_contexts = [] - for domain, contexts in old_cache.items(): - if domain not in domains: - removed_contexts.extend(contexts) - # 批量清理 - if removed_contexts: - clear_large_objects(*removed_contexts) - del old_cache return torrents_cache