mirror of
https://github.com/LC044/WeChatMsg
synced 2025-05-22 08:09:10 +08:00
1. 新增 db_pool.py 实现数据库连接池管理 2. 修改 __init__.py 导入连接池并提供关闭连接池方法 3. 优化 msg.py 中的数据库操作,提高并发性能 在处理大量数据导入时,推荐使用batch_insert_messages方法 在应用退出时应调用close_db确保资源释放 对于大量查询操作,可以进一步优化查询SQL和索引
46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
@File : __init__.py.py
|
|
@Author : Shuaikang Zhou
|
|
@Time : 2023/1/5 0:10
|
|
@IDE : Pycharm
|
|
@Version : Python3.10
|
|
@comment : ···
|
|
"""
|
|
from .hard_link import HardLink
|
|
from .micro_msg import MicroMsg
|
|
from .media_msg import MediaMsg
|
|
from .misc import Misc
|
|
from .msg import Msg
|
|
from .msg import MsgType
|
|
from .db_pool import db_pool, close_db_pool
|
|
|
|
misc_db = Misc()
|
|
msg_db = Msg()
|
|
micro_msg_db = MicroMsg()
|
|
hard_link_db = HardLink()
|
|
media_msg_db = MediaMsg()
|
|
|
|
|
|
def close_db():
|
|
"""关闭所有数据库连接"""
|
|
misc_db.close()
|
|
msg_db.close()
|
|
micro_msg_db.close()
|
|
hard_link_db.close()
|
|
media_msg_db.close()
|
|
# 关闭数据库连接池
|
|
close_db_pool()
|
|
|
|
|
|
def init_db():
|
|
"""初始化所有数据库连接"""
|
|
misc_db.init_database()
|
|
msg_db.init_database()
|
|
micro_msg_db.init_database()
|
|
hard_link_db.init_database()
|
|
media_msg_db.init_database()
|
|
|
|
|
|
__all__ = ['misc_db', 'micro_msg_db', 'msg_db', 'hard_link_db', 'MsgType', "media_msg_db", "close_db", "db_pool"]
|