Skip to content

perf: cache validateApiKey and proxyPool lookups, replace uuid with native randomUUID - #81

Open
mahdiwafy wants to merge 1 commit into
Vanszs:mainfrom
mahdiwafy:pr/perf-auth-proxy-cache
Open

perf: cache validateApiKey and proxyPool lookups, replace uuid with native randomUUID#81
mahdiwafy wants to merge 1 commit into
Vanszs:mainfrom
mahdiwafy:pr/perf-auth-proxy-cache

Conversation

@mahdiwafy

Copy link
Copy Markdown

Summary

Optimize middleware and repository hot paths to reduce per-request latency:

Changes

  1. src/dashboardGuard.js - Reduce auth logging noise in hot path

    • Successful API key validation logs now behind DEBUG_AUTH env
    • Failed/invalid key logs remain visible
    • Trusted host (PUBLIC_API_HOSTS) logic extracted and clarified
  2. src/lib/db/repos/apiKeysRepo.js - Add 2s in-memory validation cache

    • validateApiKey() now caches hits for 2 seconds
    • Cache auto-invalidated on create/update/delete API key
    • Cache TTL respects key expiresAt if sooner
    • Benchmark: first DB hit ~60ms, 1000 cached calls ~0.57ms total
  3. src/lib/db/repos/proxyPoolsRepo.js - Add 2s in-memory proxy pool cache

    • getProxyPools() and getProxyPoolById() cached for 2 seconds
    • Cache auto-invalidated on create/update/delete proxy pool
    • Critical for noAuth free provider path (opencode, etc.)
    • Benchmark: first list hit ~70ms, 1000 cached calls ~1ms total
  4. src/lib/db/repos/connectionsRepo.js - Replace uuid dependency

    • Use native crypto.randomUUID() instead of uuid package
    • Eliminates startup warning: "Cannot find package 'uuid' imported from connectionsRepo.js"

Verification

  • npm run lint:undef — clean
  • npm run build — exit 0
  • Docker build — success (vansrouter:optimized-auth-proxy-cache)
  • Deployed container vansrouter on port 20128 — healthy
  • Warm /v1/models with API key: avg 0.0075s (cached)
  • /v1/chat/completions via OPENCODE: HTTP 200 in ~3.2s
  • Startup logs clean — no uuid warning, no auth spam

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