Skip to content

Commit cc87040

Browse files
perf: User cache log
1 parent 4771f39 commit cc87040

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

backend/apps/system/middleware/auth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ async def validateToken(self, token: Optional[str]):
6363
with Session(engine) as session:
6464
session_user = await get_user_info(session = session, user_id = token_data.id)
6565
session_user = UserInfoDTO.model_validate(session_user)
66-
session_user = UserInfoDTO.model_validate(session_user)
6766
""" if token_data.oid != session_user.oid:
6867
raise HTTPException(
6968
status_code=401,

backend/common/core/sqlbot_cache.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import random
99
from collections import defaultdict
1010

11+
from apps.system.schemas.auth import CacheName
12+
from apps.system.schemas.system_schema import UserInfoDTO
1113
from common.utils.utils import SQLBotLogUtil
1214

1315
# 使用contextvar来跟踪当前线程已持有的锁
@@ -118,6 +120,9 @@ async def wrapper(*args, **kwargs):
118120
# 双重检查
119121
if (cached := await backend.get(cache_key)) is not None:
120122
SQLBotLogUtil.debug(f"Cache hit: {cache_key}")
123+
if CacheName.USER_INFO.value in cache_key:
124+
user = UserInfoDTO.model_validate(cached)
125+
SQLBotLogUtil.info(f"User cache hit: [uid: {user.id}, account: {user.account}, oid: {user.oid}]")
121126
return cached
122127

123128
# 执行函数并缓存结果
@@ -129,6 +134,9 @@ async def wrapper(*args, **kwargs):
129134
await backend.set(cache_key, result, actual_expire)
130135

131136
SQLBotLogUtil.debug(f"Cache set: {cache_key} (expire: {actual_expire}s)")
137+
if CacheName.USER_INFO.value in cache_key:
138+
user = UserInfoDTO.model_validate(result)
139+
SQLBotLogUtil.info(f"User cache set: [uid: {user.id}, account: {user.account}, oid: {user.oid}]")
132140
return result
133141

134142
return wrapper

0 commit comments

Comments
 (0)