fix: avoid auth version hot path writes

This commit is contained in:
richjohnrambo
2026-09-14 19:04:36 +08:00
parent 02eddb6010
commit 275c9e5fcd
2 changed files with 12 additions and 1 deletions
+11 -1
View File
@@ -8243,6 +8243,17 @@ func (a *adapter) TenantUserSecurityGetAuthVersion(id t.TenantID, uid t.Uid) (in
defer cancel()
}
decoded := decodeUID(uid)
var version int
err := a.db.GetContext(ctx, &version,
`SELECT auth_version FROM im_user_security WHERE user_id=?`,
decoded)
if err == nil {
return version, nil
}
if err != sql.ErrNoRows {
return 0, err
}
now := t.TimeNow()
securityID, err := nextSnowflakeID()
if err != nil {
@@ -8256,7 +8267,6 @@ func (a *adapter) TenantUserSecurityGetAuthVersion(id t.TenantID, uid t.Uid) (in
if err != nil {
return 0, err
}
var version int
err = a.db.GetContext(ctx, &version,
`SELECT auth_version FROM im_user_security WHERE user_id=?`,
decoded)
+1
View File
@@ -7099,6 +7099,7 @@ func verifyIMCodeChallenge(wrt http.ResponseWriter, req *http.Request, tenantID
func authenticateIMHTTPBearer(wrt http.ResponseWriter, req *http.Request) (*imPrincipal, bool) {
principal, err := resolveIMHTTPBearer(req)
if err != nil {
logs.Warn.Printf("im http bearer auth failed request_id=%s method=%s path=%s err=%v", req.Header.Get("X-Request-ID"), req.Method, req.URL.Path, err)
if errors.Is(err, types.ErrUnsupported) {
writeIMError(wrt, req, http.StatusInternalServerError, 90000, imReasonInternal, "internal error", nil)
} else {