chore: 添加登录计时日志并优化部署脚本

- 在登录服务中添加各步骤耗时统计日志
- 精简部署脚本,移除冗余输出与前端构建逻辑
- 更新生产环境默认监听地址为 0.0.0.0
- 延长前端请求超时时间至 120 秒
This commit is contained in:
zhangtao
2026-05-12 20:23:33 +08:00
parent 30042cd035
commit bb1cb722ed
5 changed files with 122 additions and 581 deletions
@@ -1,4 +1,5 @@
import json
import time
import uuid
from datetime import datetime, timedelta
from typing import NewType
@@ -66,6 +67,8 @@ class LoginService:
异常:
- CustomException: 认证失败时抛出异常。
"""
_t = time.time()
# 判断是否来自API文档
referer = request.headers.get("referer", "")
request_from_docs = referer.endswith(("docs", "redoc"))
@@ -79,10 +82,12 @@ class LoginService:
key=login_form.captcha_key,
captcha=login_form.captcha,
)
log.info(f"[登录计时] 验证码校验: {round((time.time()-_t)*1000,1)}ms"); _t2 = time.time()
# 用户认证
auth = AuthSchema(db=db)
user = await UserCRUD(auth).get_by_username_crud(username=login_form.username)
log.info(f"[登录计时] 数据库查询用户: {round((time.time()-_t2)*1000,1)}ms"); _t3 = time.time()
if not user:
raise CustomException(msg="用户不存在")
@@ -91,12 +96,15 @@ class LoginService:
plain_password=login_form.password, password_hash=user.password
):
raise CustomException(msg="账号或密码错误")
log.info(f"[登录计时] Bcrypt密码校验: {round((time.time()-_t3)*1000,1)}ms"); _t4 = time.time()
if user.status == "1":
raise CustomException(msg="用户已被停用")
# 更新最后登录时间
user = await UserCRUD(auth).update_last_login_crud(id=user.id)
log.info(f"[登录计时] 更新登录时间: {round((time.time()-_t4)*1000,1)}ms"); _t5 = time.time()
if not user:
raise CustomException(msg="用户不存在")
if not login_form.login_type:
@@ -109,6 +117,9 @@ class LoginService:
user=user,
login_type=login_form.login_type,
)
log.info(f"[登录计时] 创建Token(含IP解析+Redis写入+在线记录): {round((time.time()-_t5)*1000,1)}ms")
log.info(f"[登录计时] ⭐ 登录总耗时: {round((time.time()-_t)*1000,1)}ms")
return token