From 396130957caee7c0e7760d10ab0d569118e0b42a Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Tue, 23 Apr 2024 16:07:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=B1=A0=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-fastapi-backend/.env.dev | 8 ++++++++ dash-fastapi-backend/.env.prod | 8 ++++++++ dash-fastapi-backend/config/database.py | 7 ++++++- dash-fastapi-backend/config/env.py | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dash-fastapi-backend/.env.dev b/dash-fastapi-backend/.env.dev index 4923d01..3548e69 100644 --- a/dash-fastapi-backend/.env.dev +++ b/dash-fastapi-backend/.env.dev @@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot' DB_DATABASE = 'dash-fastapi' # 是否开启sqlalchemy日志 DB_ECHO = true +# 允许溢出连接池大小的最大连接数 +DB_MAX_OVERFLOW = 10 +# 连接池大小,0表示连接数无限制 +DB_POOL_SIZE = 50 +# 连接回收时间(单位:秒) +DB_POOL_RECYCLE = 3600 +# 连接池中没有线程可用时,最多等待的时间(单位:秒) +DB_POOL_TIMEOUT = 30 # -------- Redis配置 -------- # Redis主机 diff --git a/dash-fastapi-backend/.env.prod b/dash-fastapi-backend/.env.prod index 1e06e0d..a56fcb0 100644 --- a/dash-fastapi-backend/.env.prod +++ b/dash-fastapi-backend/.env.prod @@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot' DB_DATABASE = 'dash-fastapi' # 是否开启sqlalchemy日志 DB_ECHO = true +# 允许溢出连接池大小的最大连接数 +DB_MAX_OVERFLOW = 10 +# 连接池大小,0表示连接数无限制 +DB_POOL_SIZE = 50 +# 连接回收时间(单位:秒) +DB_POOL_RECYCLE = 3600 +# 连接池中没有线程可用时,最多等待的时间(单位:秒) +DB_POOL_TIMEOUT = 30 # -------- Redis配置 -------- # Redis主机 diff --git a/dash-fastapi-backend/config/database.py b/dash-fastapi-backend/config/database.py index 4f00f8b..cb871ec 100644 --- a/dash-fastapi-backend/config/database.py +++ b/dash-fastapi-backend/config/database.py @@ -8,7 +8,12 @@ SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.db_username}:{quote_ f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}" engine = create_engine( - SQLALCHEMY_DATABASE_URL, echo=DataBaseConfig.db_echo + SQLALCHEMY_DATABASE_URL, + echo=DataBaseConfig.db_echo, + max_overflow=DataBaseConfig.db_max_overflow, + pool_size=DataBaseConfig.db_pool_size, + pool_recycle=DataBaseConfig.db_pool_recycle, + pool_timeout=DataBaseConfig.db_pool_timeout ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) Base = declarative_base() diff --git a/dash-fastapi-backend/config/env.py b/dash-fastapi-backend/config/env.py index f257c1f..863719a 100644 --- a/dash-fastapi-backend/config/env.py +++ b/dash-fastapi-backend/config/env.py @@ -41,6 +41,10 @@ class DataBaseSettings(BaseSettings): db_password: str = 'mysqlroot' db_database: str = 'dash-fastapi' db_echo: bool = True + db_max_overflow: int = 10 + db_pool_size: int = 50 + db_pool_recycle: int = 3600 + db_pool_timeout: int = 30 class RedisSettings(BaseSettings): -- Gitee From e6bcb6393abe90c4d047271d55df04ecb7987120 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Wed, 24 Apr 2024 10:15:29 +0800 Subject: [PATCH 2/5] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8@lru=5Fcache?= =?UTF-8?q?=E7=BC=93=E5=AD=98ip=E5=BD=92=E5=B1=9E=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=B0=83=E7=94=A8ip=E5=BD=92=E5=B1=9E?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E4=BB=A5?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module_admin/annotation/log_annotation.py | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/dash-fastapi-backend/module_admin/annotation/log_annotation.py b/dash-fastapi-backend/module_admin/annotation/log_annotation.py index 2e12462..7c1f162 100644 --- a/dash-fastapi-backend/module_admin/annotation/log_annotation.py +++ b/dash-fastapi-backend/module_admin/annotation/log_annotation.py @@ -1,4 +1,4 @@ -from functools import wraps +from functools import wraps, lru_cache from fastapi import Request from fastapi.responses import JSONResponse, ORJSONResponse, UJSONResponse import inspect @@ -52,21 +52,7 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope oper_ip = request.headers.get('remote_addr') if request.headers.get('is_browser') == 'no' else request.headers.get('X-Forwarded-For') oper_location = '内网IP' if AppConfig.app_ip_location_query: - try: - if oper_ip != '127.0.0.1' and oper_ip != 'localhost': - ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}') - if ip_result.status_code == 200: - prov = ip_result.json().get('data').get('prov') - city = ip_result.json().get('data').get('city') - if prov or city: - oper_location = f'{prov}-{city}' - else: - oper_location = '未知' - else: - oper_location = '未知' - except Exception as e: - oper_location = '未知' - print(e) + oper_location = get_ip_location(oper_ip) # 根据不同的请求类型使用不同的方法获取请求参数 content_type = request.headers.get("Content-Type") if content_type and ("multipart/form-data" in content_type or 'application/x-www-form-urlencoded' in content_type): @@ -167,3 +153,26 @@ def log_decorator(title: str, business_type: int, log_type: Optional[str] = 'ope return wrapper return decorator + + +@lru_cache() +def get_ip_location(oper_ip: str): + """ + 查询ip归属区域 + :param oper_ip: 需要查询的ip + :return: ip归属区域 + """ + oper_location = '内网IP' + try: + if oper_ip != '127.0.0.1' and oper_ip != 'localhost': + oper_location = '未知' + ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}') + if ip_result.status_code == 200: + prov = ip_result.json().get('data').get('prov') + city = ip_result.json().get('data').get('city') + if prov or city: + oper_location = f'{prov}-{city}' + except Exception as e: + oper_location = '未知' + print(e) + return oper_location -- Gitee From a4f27d692554fb5f0442ebcfe25e9e30a4e01297 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 28 Apr 2024 22:05:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=81=9C=E7=94=A8=E3=80=81=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=81=9C=E7=94=A8=E6=88=96=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E5=B7=B2=E5=88=A0=E9=99=A4=E6=97=B6=E8=8E=B7=E5=8F=96=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E4=BF=A1=E6=81=AF=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-fastapi-backend/module_admin/dao/role_dao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash-fastapi-backend/module_admin/dao/role_dao.py b/dash-fastapi-backend/module_admin/dao/role_dao.py index 8ed51b4..7e2624f 100644 --- a/dash-fastapi-backend/module_admin/dao/role_dao.py +++ b/dash-fastapi-backend/module_admin/dao/role_dao.py @@ -73,12 +73,12 @@ class RoleDao: query_role_menu_info = db.query(SysMenu).select_from(SysRole) \ .filter(SysRole.del_flag == 0, SysRole.role_id == role_id) \ .outerjoin(SysRoleMenu, SysRole.role_id == SysRoleMenu.role_id) \ - .outerjoin(SysMenu, and_(SysRoleMenu.menu_id == SysMenu.menu_id, SysMenu.status == 0)) \ + .join(SysMenu, and_(SysRoleMenu.menu_id == SysMenu.menu_id, SysMenu.status == 0)) \ .distinct().all() query_role_dept_info = db.query(SysDept).select_from(SysRole) \ .filter(SysRole.del_flag == 0, SysRole.role_id == role_id) \ .outerjoin(SysRoleDept, SysRole.role_id == SysRoleDept.role_id) \ - .outerjoin(SysDept, and_(SysRoleDept.dept_id == SysDept.dept_id, SysDept.status == 0, SysDept.del_flag == 0)) \ + .join(SysDept, and_(SysRoleDept.dept_id == SysDept.dept_id, SysDept.status == 0, SysDept.del_flag == 0)) \ .distinct().all() results = dict( role=object_format_datetime(query_role_basic_info), -- Gitee From 1a676b2fe6149d6fe985f9f20b8595dcdce109b9 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Mon, 29 Apr 2024 08:59:27 +0800 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=87=B31.4.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-fastapi-backend/.env.dev | 2 +- dash-fastapi-backend/.env.prod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dash-fastapi-backend/.env.dev b/dash-fastapi-backend/.env.dev index 3548e69..27b925e 100644 --- a/dash-fastapi-backend/.env.dev +++ b/dash-fastapi-backend/.env.dev @@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0' # 应用端口 APP_PORT = 9099 # 应用版本 -APP_VERSION= '1.4.0' +APP_VERSION= '1.4.1' # 应用是否开启热重载 APP_RELOAD = true # 应用是否开启IP归属区域查询 diff --git a/dash-fastapi-backend/.env.prod b/dash-fastapi-backend/.env.prod index a56fcb0..f73763c 100644 --- a/dash-fastapi-backend/.env.prod +++ b/dash-fastapi-backend/.env.prod @@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0' # 应用端口 APP_PORT = 9099 # 应用版本 -APP_VERSION= '1.4.0' +APP_VERSION= '1.4.1' # 应用是否开启热重载 APP_RELOAD = false # 应用是否开启IP归属区域查询 -- Gitee From d504a808a67cb92161ac9731fd128f3c85e5a0b4 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Mon, 29 Apr 2024 08:59:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0README=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0fe715c..35d5ebc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

logo

-

Dash-FastAPI-Admin v1.4.0

+

Dash-FastAPI-Admin v1.4.1

基于Dash+FastAPI前后端分离的纯Python快速开发框架

- + @@ -17,6 +17,7 @@ + ## 平台简介 Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。 -- Gitee