This commit is contained in:
jxxghp
2025-06-06 15:37:02 +08:00
parent 349535557f
commit f484b64be3
3 changed files with 1 additions and 37 deletions

View File

@@ -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:

View File

@@ -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:
# 搜索或订阅

View File

@@ -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