mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 09:17:06 +08:00
perf: User cache log
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user