Skip to content

perf(auth): 延长 API Key 校验缓存 TTL - #287

Merged
g1331 merged 1 commit into
masterfrom
perf/api-key-cache-ttl
Aug 21, 2026
Merged

perf(auth): 延长 API Key 校验缓存 TTL#287
g1331 merged 1 commit into
masterfrom
perf/api-key-cache-ttl

Conversation

@g1331

@g1331 g1331 commented Aug 21, 2026

Copy link
Copy Markdown
Owner

Summary

将 API Key bcrypt 成功校验缓存 TTL 从 10 秒延长到 120 秒,匹配生产请求间隔,降低重复请求的 cold-path 认证开销。

Related Issue

无。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (code improvement without changing functionality)
  • Tests (adding or updating tests)
  • Build/CI (changes to build system or CI configuration)

Changes

  • API_KEY_VERIFY_CACHE_TTL_MS: 10_000120_000
  • 保持缓存容量 2048 不变。
  • 增加 TTL 边界测试:119999ms 内命中,120000ms 后重新执行 bcrypt。
  • 缓存仍只跳过 bcrypt;active、expiry、owner、upstream authorization 仍由每请求数据库路径校验。

Test Plan

  • pnpm test:run tests/unit/utils/auth.test.ts
  • pnpm exec tsc --noEmit
  • pnpm lint
  • Manual testing completed

Checklist

  • Code follows the project's coding standards
  • Tests have been added where necessary
  • Documentation has been updated (not applicable)
  • Changes do not introduce security vulnerabilities
  • Commit messages follow conventions

Additional Notes

生产日志调查显示 beta3 发布后的请求间隔 P50 约 25 秒、P75 约 106 秒;10 秒 TTL 在最新请求中没有命中,120 秒覆盖当前样本约 63% 的相邻请求。

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.54%. Comparing base (5d9fa75) to head (ca6191a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
+ Coverage   72.50%   72.54%   +0.04%     
==========================================
  Files         245      245              
  Lines       14519    14519              
  Branches     4836     4836              
==========================================
+ Hits        10527    10533       +6     
+ Misses       2605     2600       -5     
+ Partials     1387     1386       -1     
Flag Coverage Δ
verify 72.54% <100.00%> (+0.04%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@g1331
g1331 merged commit 5c42775 into master Aug 21, 2026
12 checks passed
@g1331
g1331 deleted the perf/api-key-cache-ttl branch August 21, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant