fix: 修复数据库连接没有关闭问题 (#7227)

* fix: 修复数据库连接没有关闭的bug

perf: websocket 断开也添加关闭数据库连接

* fix: 修复数据库连接没有关闭问题

Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
fit2bot
2021-11-18 18:47:01 +08:00
committed by GitHub
parent 6e5dcc738e
commit d2df8acd84
9 changed files with 87 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
from common.utils import get_logger
from django.db import connections
logger = get_logger(__file__)
@@ -38,3 +39,8 @@ def get_objects(model, pks):
not_found_pks = pks - exists_pks
logger.error(f'DoesNotExist: <{model.__name__}: {not_found_pks}>')
return objs
def close_old_connections():
for conn in connections.all():
conn.close_if_unusable_or_obsolete()