mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import copy
|
import copy
|
||||||
import gc
|
|
||||||
import pickle
|
import pickle
|
||||||
import traceback
|
import traceback
|
||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
@@ -69,10 +68,6 @@ class ChainBase(metaclass=ABCMeta):
|
|||||||
pickle.dump(cache, f) # noqa
|
pickle.dump(cache, f) # noqa
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"保存缓存 {filename} 出错:{str(err)}")
|
logger.error(f"保存缓存 {filename} 出错:{str(err)}")
|
||||||
finally:
|
|
||||||
# 主动资源回收
|
|
||||||
del cache
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remove_cache(filename: str) -> None:
|
def remove_cache(filename: str) -> None:
|
||||||
|
|||||||
@@ -265,10 +265,6 @@ class MessageChain(ChainBase):
|
|||||||
userid=userid,
|
userid=userid,
|
||||||
total=len(contexts))
|
total=len(contexts))
|
||||||
|
|
||||||
# 清理内存
|
|
||||||
del cache_list
|
|
||||||
del cache_data
|
|
||||||
|
|
||||||
elif cache_type in ["Subscribe", "ReSubscribe"]:
|
elif cache_type in ["Subscribe", "ReSubscribe"]:
|
||||||
# 订阅或洗版媒体
|
# 订阅或洗版媒体
|
||||||
mediainfo: MediaInfo = cache_list[_choice]
|
mediainfo: MediaInfo = cache_list[_choice]
|
||||||
@@ -357,9 +353,6 @@ class MessageChain(ChainBase):
|
|||||||
items=cache_list[start:end],
|
items=cache_list[start:end],
|
||||||
userid=userid,
|
userid=userid,
|
||||||
total=len(cache_list))
|
total=len(cache_list))
|
||||||
# 清理内存
|
|
||||||
del cache_list
|
|
||||||
del cache_data
|
|
||||||
|
|
||||||
elif text.lower() == "n":
|
elif text.lower() == "n":
|
||||||
# 下一页
|
# 下一页
|
||||||
@@ -396,9 +389,6 @@ class MessageChain(ChainBase):
|
|||||||
source=source,
|
source=source,
|
||||||
title=_current_meta.name,
|
title=_current_meta.name,
|
||||||
items=cache_list, userid=userid, total=total)
|
items=cache_list, userid=userid, total=total)
|
||||||
# 清理内存
|
|
||||||
del cache_list
|
|
||||||
del cache_data
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# 搜索或订阅
|
# 搜索或订阅
|
||||||
|
|||||||
+1
-22
@@ -1,4 +1,3 @@
|
|||||||
import gc
|
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Dict, List, Union, Optional
|
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.core.metainfo import MetaInfo
|
||||||
from app.db.site_oper import SiteOper
|
from app.db.site_oper import SiteOper
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
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.rss import RssHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.helper.torrent import TorrentHelper
|
from app.helper.torrent import TorrentHelper
|
||||||
@@ -221,17 +220,7 @@ class TorrentsChain(ChainBase):
|
|||||||
torrents_cache[domain].append(context)
|
torrents_cache[domain].append(context)
|
||||||
# 如果超过了限制条数则移除掉前面的
|
# 如果超过了限制条数则移除掉前面的
|
||||||
if len(torrents_cache[domain]) > settings.CACHE_CONF["torrents"]:
|
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"]:]
|
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:
|
else:
|
||||||
logger.info(f'{indexer.get("name")} 没有获取到种子')
|
logger.info(f'{indexer.get("name")} 没有获取到种子')
|
||||||
|
|
||||||
@@ -243,17 +232,7 @@ class TorrentsChain(ChainBase):
|
|||||||
|
|
||||||
# 去除不在站点范围内的缓存种子
|
# 去除不在站点范围内的缓存种子
|
||||||
if sites and torrents_cache:
|
if sites and torrents_cache:
|
||||||
old_cache = torrents_cache
|
|
||||||
torrents_cache = {k: v for k, v in torrents_cache.items() if k in domains}
|
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
|
return torrents_cache
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user