rollback code
This commit is contained in:
@@ -218,10 +218,6 @@ This email was sent automatically, please do not reply.
|
||||
# 生成新的验证码
|
||||
code = EmailVerificationService.generate_verification_code()
|
||||
|
||||
# 解析用户代理字符串
|
||||
from app.utils import parse_user_agent
|
||||
parsed_user_agent = parse_user_agent(user_agent, max_length=255)
|
||||
|
||||
# 创建验证记录
|
||||
verification = EmailVerification(
|
||||
user_id=user_id,
|
||||
@@ -229,7 +225,7 @@ This email was sent automatically, please do not reply.
|
||||
verification_code=code,
|
||||
expires_at=datetime.now(UTC) + timedelta(minutes=10), # 10分钟过期
|
||||
ip_address=ip_address,
|
||||
user_agent=parsed_user_agent # 使用解析后的用户代理
|
||||
user_agent=user_agent
|
||||
)
|
||||
|
||||
db.add(verification)
|
||||
@@ -392,18 +388,13 @@ class LoginSessionService:
|
||||
is_new_location: bool = False
|
||||
) -> LoginSession:
|
||||
"""创建登录会话"""
|
||||
from app.utils import parse_user_agent
|
||||
|
||||
# 解析用户代理字符串,提取关键信息
|
||||
parsed_user_agent = parse_user_agent(user_agent, max_length=255)
|
||||
|
||||
session_token = EmailVerificationService.generate_session_token()
|
||||
|
||||
session = LoginSession(
|
||||
user_id=user_id,
|
||||
session_token=session_token,
|
||||
ip_address=ip_address,
|
||||
user_agent=parsed_user_agent, # 使用解析后的用户代理
|
||||
user_agent=user_agent,
|
||||
country_code=country_code,
|
||||
is_new_location=is_new_location,
|
||||
expires_at=datetime.now(UTC) + timedelta(hours=24), # 24小时过期
|
||||
|
||||
@@ -20,7 +20,6 @@ async def maintain_playing_users_online_status():
|
||||
|
||||
定期刷新正在游玩用户的metadata在线标记,
|
||||
确保他们在游玩过程中显示为在线状态。
|
||||
但不会恢复已经退出的用户的在线状态。
|
||||
"""
|
||||
redis_sync = get_redis_message()
|
||||
redis_async = get_redis()
|
||||
@@ -32,25 +31,17 @@ async def maintain_playing_users_online_status():
|
||||
if not playing_users:
|
||||
return
|
||||
|
||||
logger.debug(f"Checking online status for {len(playing_users)} playing users")
|
||||
logger.debug(f"Maintaining online status for {len(playing_users)} playing users")
|
||||
|
||||
# 仅为当前有效连接的用户刷新在线状态
|
||||
updated_count = 0
|
||||
# 为每个游玩用户刷新metadata在线标记
|
||||
for user_id in playing_users:
|
||||
user_id_str = user_id.decode() if isinstance(user_id, bytes) else str(user_id)
|
||||
metadata_key = f"metadata:online:{user_id_str}"
|
||||
|
||||
# 重要:首先检查用户是否已经有在线标记,只有存在才刷新
|
||||
if await redis_async.exists(metadata_key):
|
||||
# 只更新已经在线的用户的状态,不恢复已退出的用户
|
||||
await redis_async.set(metadata_key, "playing", ex=3600)
|
||||
updated_count += 1
|
||||
else:
|
||||
# 如果用户已退出(没有在线标记),则从游玩用户中移除
|
||||
await _redis_exec(redis_sync.srem, REDIS_PLAYING_USERS_KEY, user_id)
|
||||
logger.debug(f"Removed user {user_id_str} from playing users as they are offline")
|
||||
# 设置或刷新metadata在线标记,过期时间为1小时
|
||||
await redis_async.set(metadata_key, "playing", ex=3600)
|
||||
|
||||
logger.debug(f"Updated metadata online status for {updated_count} playing users")
|
||||
logger.debug(f"Updated metadata online status for {len(playing_users)} playing users")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error maintaining playing users online status: {e}")
|
||||
|
||||
@@ -358,7 +358,9 @@ class RedisMessageSystem:
|
||||
# 确保消息按ID正序排序(时间顺序)
|
||||
messages.sort(key=lambda x: x.get("message_id", 0))
|
||||
|
||||
return messages
|
||||
# 如果是获取最新消息(since=0),需要保持倒序(最新的在前面)
|
||||
if since == 0:
|
||||
messages.reverse()
|
||||
|
||||
return messages
|
||||
|
||||
|
||||
Reference in New Issue
Block a user