diff --git a/backend/apps/system/middleware/auth.py b/backend/apps/system/middleware/auth.py index a1e7b1e2..23bdd512 100644 --- a/backend/apps/system/middleware/auth.py +++ b/backend/apps/system/middleware/auth.py @@ -63,7 +63,6 @@ class TokenMiddleware(BaseHTTPMiddleware): with Session(engine) as session: session_user = await get_user_info(session = session, user_id = token_data.id) session_user = UserInfoDTO.model_validate(session_user) - session_user = UserInfoDTO.model_validate(session_user) """ if token_data.oid != session_user.oid: raise HTTPException( status_code=401, diff --git a/backend/common/core/sqlbot_cache.py b/backend/common/core/sqlbot_cache.py index e3fe8482..15d58308 100644 --- a/backend/common/core/sqlbot_cache.py +++ b/backend/common/core/sqlbot_cache.py @@ -8,6 +8,8 @@ import asyncio import random from collections import defaultdict +from apps.system.schemas.auth import CacheName +from apps.system.schemas.system_schema import UserInfoDTO from common.utils.utils import SQLBotLogUtil # 使用contextvar来跟踪当前线程已持有的锁 @@ -118,6 +120,9 @@ def cache( # 双重检查 if (cached := await backend.get(cache_key)) is not None: SQLBotLogUtil.debug(f"Cache hit: {cache_key}") + if CacheName.USER_INFO.value in cache_key: + user = UserInfoDTO.model_validate(cached) + SQLBotLogUtil.info(f"User cache hit: [uid: {user.id}, account: {user.account}, oid: {user.oid}]") return cached # 执行函数并缓存结果 @@ -129,6 +134,9 @@ def cache( await backend.set(cache_key, result, actual_expire) SQLBotLogUtil.debug(f"Cache set: {cache_key} (expire: {actual_expire}s)") + if CacheName.USER_INFO.value in cache_key: + user = UserInfoDTO.model_validate(result) + SQLBotLogUtil.info(f"User cache set: [uid: {user.id}, account: {user.account}, oid: {user.oid}]") return result return wrapper