fix 数据库连接复用
This commit is contained in:
@ -5,6 +5,7 @@ from typing import Any, List, Dict, Tuple
|
||||
from app.chain import ChainBase
|
||||
from app.core.config import settings
|
||||
from app.core.event import EventManager
|
||||
from app.db import SessionLocal
|
||||
from app.db.models import Base
|
||||
from app.db.plugindata_oper import PluginDataOper
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
@ -37,10 +38,12 @@ class _PluginBase(metaclass=ABCMeta):
|
||||
plugin_desc: str = ""
|
||||
|
||||
def __init__(self):
|
||||
# 数据库连接
|
||||
self.db = SessionLocal()
|
||||
# 插件数据
|
||||
self.plugindata = PluginDataOper()
|
||||
self.plugindata = PluginDataOper(self.db)
|
||||
# 处理链
|
||||
self.chain = PluginChian()
|
||||
self.chain = PluginChian(self.db)
|
||||
# 系统配置
|
||||
self.systemconfig = SystemConfigOper()
|
||||
# 系统消息
|
||||
|
@ -62,7 +62,7 @@ class BestFilmVersion(_PluginBase):
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self._cache_path = settings.TEMP_PATH / "__best_film_version_cache__"
|
||||
self.subscribechain = SubscribeChain()
|
||||
self.subscribechain = SubscribeChain(self.db)
|
||||
|
||||
# 停止现有任务
|
||||
self.stop_service()
|
||||
|
@ -90,9 +90,9 @@ class DirMonitor(_PluginBase):
|
||||
tr = None
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self.transferhis = TransferHistoryOper()
|
||||
self.downloadhis = DownloadHistoryOper()
|
||||
self.transferchian = TransferChain()
|
||||
self.transferhis = TransferHistoryOper(self.db)
|
||||
self.downloadhis = DownloadHistoryOper(self.db)
|
||||
self.transferchian = TransferChain(self.db)
|
||||
|
||||
# 清空配置
|
||||
self._dirconf = {}
|
||||
|
@ -65,8 +65,8 @@ class DoubanRank(_PluginBase):
|
||||
_clearflag = False
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self.downloadchain = DownloadChain()
|
||||
self.subscribechain = SubscribeChain()
|
||||
self.downloadchain = DownloadChain(self.db)
|
||||
self.subscribechain = SubscribeChain(self.db)
|
||||
|
||||
if config:
|
||||
self._enabled = config.get("enabled")
|
||||
|
@ -66,9 +66,9 @@ class DoubanSync(_PluginBase):
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self.rsshelper = RssHelper()
|
||||
self.downloadchain = DownloadChain()
|
||||
self.searchchain = SearchChain()
|
||||
self.subscribechain = SubscribeChain()
|
||||
self.downloadchain = DownloadChain(self.db)
|
||||
self.searchchain = SearchChain(self.db)
|
||||
self.subscribechain = SubscribeChain(self.db)
|
||||
|
||||
# 停止现有任务
|
||||
self.stop_service()
|
||||
|
@ -61,7 +61,7 @@ class MediaSyncDel(_PluginBase):
|
||||
tr = None
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self._transferhis = TransferHistoryOper()
|
||||
self._transferhis = TransferHistoryOper(self.db)
|
||||
self.episode = Episode()
|
||||
self.qb = Qbittorrent()
|
||||
self.tr = Transmission()
|
||||
|
@ -51,9 +51,9 @@ class NAStoolSync(_PluginBase):
|
||||
tr = None
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self._transferhistory = TransferHistoryOper()
|
||||
self._plugindata = PluginDataOper()
|
||||
self._downloadhistory = DownloadHistoryOper()
|
||||
self._transferhistory = TransferHistoryOper(self.db)
|
||||
self._plugindata = PluginDataOper(self.db)
|
||||
self._downloadhistory = DownloadHistoryOper(self.db)
|
||||
|
||||
if config:
|
||||
self._clear = config.get("clear")
|
||||
|
@ -70,9 +70,9 @@ class RssSubscribe(_PluginBase):
|
||||
|
||||
def init_plugin(self, config: dict = None):
|
||||
self.rsshelper = RssHelper()
|
||||
self.downloadchain = DownloadChain()
|
||||
self.searchchain = SearchChain()
|
||||
self.subscribechain = SubscribeChain()
|
||||
self.downloadchain = DownloadChain(self.db)
|
||||
self.searchchain = SearchChain(self.db)
|
||||
self.subscribechain = SubscribeChain(self.db)
|
||||
|
||||
# 停止现有任务
|
||||
self.stop_service()
|
||||
|
Reference in New Issue
Block a user