fix(indexer): remove duplicate schema block and fix rate-limit bugs from #207#208
Merged
Conversation
…rom PR #207 - schema.sql: delete the duplicate rate-limit block (lines 50-200) that PR #207 inserted above the canonical '─── IP Rate Limiting ───' section. Both blocks used CREATE IF NOT EXISTS / CREATE OR REPLACE, so the second block always silently overwrote the first; any fix in the new block was a no-op in production. - schema.sql consume_rate_limit_bucket: fix retryAfter returning >= 1 even for allowed requests. Changed greatest(..., 1) to a CASE that returns 0 when count <= p_limit, matching the contract of acquire_sse_connection. - schema.sql acquire_sse_connection: replace pg_advisory_xact_lock(hashtext(p_key)) with pg_advisory_xact_lock(hashtext('rl_sse'), hashtext(p_key)) to avoid int4 hash collisions across unrelated SSE keys serializing each other. - schema.sql: remove WHAT-level comment line from the canonical block header. - package.json: fix test:scripts from "node --test scripts/test-scripts.js test/*.test.js" to "node scripts/test-scripts.js". The original mixed vitest-based test files (rateLimiter.test.js) into a node --test invocation that would see 0 tests and report a false pass; scripts/test-scripts.js also does not use the node:test API so --test was wrong for it too. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JfnhH2CghRyxav22rfM8bQ
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Correcciones sobre los bugs encontrados en la revisión del PR #207 (ya mergeado).
schema.sql— bloque duplicado eliminado: PR #147 global rate limiting by ip on public indexer endpoints fix #207 insertó el bloque completo de rate-limit (tablas + 5 funciones) antes de la secciónalter publication supabase_realtime, pero el mismo bloque ya existía más abajo bajo-- ─── IP Rate Limiting ───. ConCREATE IF NOT EXISTS/CREATE OR REPLACEel segundo bloque sobreescribía silenciosamente al primero en cada migración — cualquier corrección en el bloque nuevo era no-op en producción. Se elimina el bloque duplicado (157 líneas) y se aplican los fixes directamente al bloque canónico.schema.sqlconsume_rate_limit_bucket—retryAftercorregido:greatest(ceil(...), 1)devolvía ≥ 1 incluso para peticiones permitidas, produciendo{ allowed: true, retryAfter: 37 }— contrato roto. Cambiado aCASE WHEN count > p_limit THEN ... ELSE 0 ENDpara ser consistente conacquire_sse_connection.schema.sqlacquire_sse_connection— colisión de advisory lock:pg_advisory_xact_lock(hashtext(p_key))usa int4 (32 bits); dos IPs distintas pueden colisionar y serializar conexiones SSE sin relación. Cambiado apg_advisory_xact_lock(hashtext('rl_sse'), hashtext(p_key))(overload de dos int4 = espacio de 64 bits efectivos).package.jsontest:scripts: corregido denode --test scripts/test-scripts.js test/*.test.jsanode scripts/test-scripts.js. El comando original pasabatest/rateLimiter.test.js(que importa de vitest) al runner denode --test, que reportaba 0 tests y un falso verde.scripts/test-scripts.jstampoco usa la APInode:testpor lo que--testera incorrecto.Test plan
node -e "require('./bimex-indexer/package.json')"— JSON válidonpm run testenbimex-indexer/— suite vitest pasanpm run test:scriptsenbimex-indexer/— ejecuta el script estructural sin errorGenerated by Claude Code