fix: 收尾 P2——登录恒定耗时、AdminUsage N+1、用量索引重塑与时区缝

- 登录失败路径补 argon2 恒定耗时校验(用户不存在/被禁用与密码错误的时序不可区分,抹掉用户名枚举面)
- AdminUsage 每行 2 次查询改批量预取(100 行分页省 200 次查询)
- usage_logs 补 key_id 索引与 (user,created)/(channel,created) 复合索引(schema v6);AutoMigrate 按名跳过已存在索引,旧库的复合索引需一次性删掉重建,用 system_configs 打标记防 PG 每次启动重演
- 用量统计默认窗口改 UTC(usage_daily 的 date 键是 UTC,非 UTC 服务器上图表窗口偏移一天)
- 注册 email 大小写归一;并发撞唯一索引回查后返回 409 而非 500
- PatchKey 的 name 校验与 CreateKey 对齐(1-64 字符),PATCH 不再能绕过
- TrendChart 条宽不超过槽位(点数多时不再互相重叠),超过 32 个点隐藏标签行
This commit is contained in:
Sakurasan committed 2026-10-29 03:05:56 +08:00
1 parent 4df2506a74
commit 1f8af649ca
7 files changed
+107 -21

No files matched your search

+8 -1
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"net/http"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -140,7 +141,13 @@ func (h *Handler) PatchKey(c *gin.Context) {
}
updates := map[string]any{}
if req.Name != nil {
updates["name"] = *req.Name
// 与 CreateKey 的 1-64 校验对齐,PATCH 不能绕过
nm := strings.TrimSpace(*req.Name)
if len(nm) < 1 || len(nm) > 64 {
resp.Fail(c, http.StatusBadRequest, "name must be 1-64 chars")
return
}
updates["name"] = nm
}
// 限额:>0 生效,0 或负数视为"不限制"(写 NULL)。
// 不能存 0:token 配额判定是 `已用 >= 上限`,0 会让密钥第一次请求就被 429 打死。