Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions backend/middleware/i18n_middleware.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from collections.abc import Callable
from functools import lru_cache

from fastapi import Request, Response
from starlette.middleware.base import BaseHTTPMiddleware

from backend.common.i18n import i18n


@lru_cache
def get_current_language(request: Request) -> str | None:
"""
获取当前请求的语言偏好
Expand Down
4 changes: 4 additions & 0 deletions backend/plugin/code_generator/utils/type_conversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from functools import lru_cache

from backend.core.conf import settings
from backend.plugin.code_generator.enums import GenMySQLColumnType, GenPostgreSQLColumnType


@lru_cache(maxsize=128)
def sql_type_to_sqlalchemy(typing: str) -> str:
"""
将 SQL 类型转换为 SQLAlchemy 类型
Expand All @@ -18,6 +21,7 @@ def sql_type_to_sqlalchemy(typing: str) -> str:
return 'String'


@lru_cache(maxsize=128)
def sql_type_to_pydantic(typing: str) -> str:
"""
将 SQL 类型转换为 Pydantic 类型
Expand Down
55 changes: 25 additions & 30 deletions backend/utils/dynamic_config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from functools import lru_cache

from sqlalchemy import inspect
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession
from sqlalchemy.ext.asyncio import AsyncSession

from backend.core.conf import settings
from backend.database.db import async_engine
from backend.utils.serializers import select_list_serialize

_sys_config_table_exists: bool | None = None


@lru_cache
def get_sys_config_table(conn: AsyncConnection) -> bool:
async def check_sys_config_table_exists() -> bool:
"""
获取参数配置表
检查 sys_config 表是否存在

:param conn: 数据库连接
:return:
"""
inspector = inspect(conn)
return inspector.has_table('sys_config', schema=None)
global _sys_config_table_exists
if _sys_config_table_exists is None:
async with async_engine.begin() as conn:
_sys_config_table_exists = await conn.run_sync(lambda c: inspect(c).has_table('sys_config', schema=None))
return _sys_config_table_exists


async def load_user_security_config(db: AsyncSession) -> None: # noqa: C901
Expand All @@ -27,15 +28,13 @@ async def load_user_security_config(db: AsyncSession) -> None: # noqa: C901
:param db: 数据库会话
:return:
"""
dynamic_config = None
if not await check_sys_config_table_exists():
return

async with async_engine.begin() as conn:
exists = await conn.run_sync(get_sys_config_table)
if exists:
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType

dynamic_config = await config_dao.get_all(db, ConfigType.user_security)
dynamic_config = await config_dao.get_all(db, ConfigType.user_security)

if dynamic_config:
security_config_status_key = 'USER_SECURITY_CONFIG_STATUS'
Expand Down Expand Up @@ -75,15 +74,13 @@ async def load_login_config(db: AsyncSession) -> None:
:param db: 数据库会话
:return:
"""
dynamic_config = None
if not await check_sys_config_table_exists():
return

async with async_engine.begin() as conn:
exists = await conn.run_sync(get_sys_config_table)
if exists:
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType

dynamic_config = await config_dao.get_all(db, ConfigType.login)
dynamic_config = await config_dao.get_all(db, ConfigType.login)

if dynamic_config:
login_config_status_key = 'LOGIN_CONFIG_STATUS'
Expand All @@ -101,15 +98,13 @@ async def load_email_config(db: AsyncSession) -> None:
:param db: 数据库会话
:return:
"""
dynamic_config = None
if not await check_sys_config_table_exists():
return

async with async_engine.begin() as conn:
exists = await conn.run_sync(get_sys_config_table)
if exists:
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType
from backend.plugin.config.crud.crud_config import config_dao
from backend.plugin.config.enums import ConfigType

dynamic_config = await config_dao.get_all(db, ConfigType.email)
dynamic_config = await config_dao.get_all(db, ConfigType.email)

if dynamic_config:
email_config_status_key = 'EMAIL_CONFIG_STATUS'
Expand Down