From a034aa4bf62e7f493a2ff80f231bdc5ccf17e298 Mon Sep 17 00:00:00 2001
From: zhouping <zhouping@supervision.ltd>
Date: Mon, 24 Jun 2024 17:23:46 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E8=A1=8C=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 website/db_mysql.py                           | 31 ++++++++++---------
 website/handlers/enterprise_entity/handler.py |  1 +
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/website/db_mysql.py b/website/db_mysql.py
index fcb7698..a76bd0e 100644
--- a/website/db_mysql.py
+++ b/website/db_mysql.py
@@ -1,31 +1,30 @@
-import itertools
 import contextlib
-import logging
-
+import itertools
+from contextlib import asynccontextmanager
 from typing import List, Any, Optional
 
-from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy.orm import sessionmaker
 from sqlalchemy import create_engine
 from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
-from contextlib import asynccontextmanager
+from sqlalchemy.orm import sessionmaker
 
 from website import settings
+from website.handler import Row
 
 
-class Row(dict):
-    """A dict that allows for object-like property access syntax."""
-
-    def __getattr__(self, name):
-        try:
-            return self[name]
-        except KeyError:
-            raise AttributeError(name)
+# class Row(dict):
+#     """A dict that allows for object-like property access syntax."""
+#
+#     def __getattr__(self, name):
+#         try:
+#             return self[name]
+#         except KeyError:
+#             raise AttributeError(name)
 
 
 def dict_to_obj(d):
     return type('GenericClass', (object,), d)()
 
+
 def to_json_list(cursor: Any) -> Optional[List[Row]]:
     column_names = list(cursor.keys())
     result = cursor.fetchall()
@@ -59,7 +58,9 @@ app_engine = create_engine(
     pool_recycle=int(settings.SQLALCHEMY_POOL_RECYCLE),  # 多久时间回收连接
 )
 
-Session = sessionmaker(bind=app_engine)
+Session = sessionmaker(bind=app_engine, expire_on_commit=False)
+
+
 # Base = declarative_base(app_engine)
 
 
diff --git a/website/handlers/enterprise_entity/handler.py b/website/handlers/enterprise_entity/handler.py
index d16e15b..9a41d40 100644
--- a/website/handlers/enterprise_entity/handler.py
+++ b/website/handlers/enterprise_entity/handler.py
@@ -86,6 +86,7 @@ class EntityIndexHandler(APIHandler):
         #     model_counts = [result[0] for result in results]
         #     device_counts = [result[1] for result in results]
 
+        # *用于解包参数列表,将列表中的每个元素作为单独的参数传递给asyncio.gather函数
         count_results = await asyncio.gather(
             *[
                 enterprise.get_enterprise_model_and_device_count(entity_id=item["id"])