Files
Paijo 66cb93f9bd perf: thread pre-fetched token to checkRateLimit avoiding re-query (#6930)
* perf: thread pre-fetched token to checkRateLimit avoiding re-query

getRelayTokenByHash already fetches the full RelayToken row. A few
lines later checkRateLimit(token.id) does a second SELECT * FROM
relay_tokens on a different predicate (id instead of token_hash).

Change:
- checkRateLimit accepts an optional existingToken parameter; when
  provided, skips the re-query entirely.
- Both relay routes (chat completions + bifrost) pass the already-
  fetched token.
- The function now uses RelayToken (camelCase) instead of RelayTokenRow
  (snake_case) when the token is passed in.

PR-URL: fix-relay-thread-token

* test(db): add regression coverage for checkRateLimit existingToken fast-path

Adds node:test coverage for src/lib/db/relayProxies.ts::checkRateLimit
proving the existingToken fast-path (pre-fetched RelayToken threaded in,
no re-query) agrees with the legacy re-query path (no token passed),
and that the per-minute cap is still enforced through the fast-path.
Also adds a changelog.d fragment for the perf fix in 9d4cd90e7.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-12 10:30:26 -03:00
..
2026-05-04 10:52:28 -03:00
2026-07-02 10:47:13 -03:00
2026-07-02 10:47:13 -03:00
2026-07-04 13:00:30 -03:00
2026-07-02 10:47:13 -03:00
2026-06-19 06:49:01 -03:00
2026-06-20 14:55:24 -03:00
2026-06-20 14:55:24 -03:00
2026-07-04 13:00:30 -03:00
2026-05-24 18:05:58 -03:00
2026-07-02 10:47:13 -03:00
2026-07-02 10:47:13 -03:00
2026-06-11 18:52:29 -03:00
2026-06-25 13:17:40 -03:00
2026-07-04 13:00:30 -03:00
2026-05-26 23:51:47 -03:00
2026-07-06 02:25:17 -03:00
2026-06-29 16:51:03 -03:00
2026-06-29 08:40:06 -03:00
2026-07-06 02:25:17 -03:00
2026-06-25 13:17:40 -03:00
2026-05-26 23:51:47 -03:00
2026-07-04 13:00:30 -03:00
2026-07-06 02:25:17 -03:00
2026-05-26 23:51:47 -03:00
2026-05-23 01:46:59 -03:00
2026-05-26 23:51:47 -03:00
2026-06-11 18:52:29 -03:00
2026-05-23 01:46:59 -03:00
2026-05-24 18:05:58 -03:00
2026-05-24 18:05:58 -03:00
2026-07-07 13:14:06 -03:00
2026-06-12 23:49:22 -03:00
2026-07-02 10:47:13 -03:00
2026-06-11 18:52:29 -03:00
2026-07-07 13:14:06 -03:00
2026-06-22 03:17:02 -03:00
2026-06-04 20:05:38 -03:00
2026-06-11 18:52:29 -03:00
2026-06-25 13:17:40 -03:00
2026-07-02 10:47:13 -03:00
2026-06-27 09:07:12 -03:00
2026-07-07 13:14:06 -03:00
2026-07-06 02:25:17 -03:00
2026-06-11 18:52:29 -03:00
2026-05-26 23:51:47 -03:00
2026-06-11 18:52:29 -03:00
2026-05-21 01:29:12 -03:00
2026-06-23 17:06:18 -03:00
2026-05-29 12:44:29 -03:00
2026-06-13 17:27:40 -03:00
2026-06-11 18:52:29 -03:00
2026-06-23 17:06:18 -03:00
2026-05-26 23:51:47 -03:00
2026-06-30 06:54:29 -03:00
2026-05-26 23:51:47 -03:00
2026-06-27 09:07:12 -03:00