Repository navigation
perf: unique index on publishers.api_key_hash (#41) - #143
Merged
victorisiguzoruzoma874 merged 2 commits intoOct 19, 2026
Merged
victorisiguzoruzoma874 merged 2 commits into
victorisiguzoruzoma874 merged 2 commits into
Conversation
Every authenticated request queries publishers by api_key_hash. Without
an index this is a sequential scan; with a unique index it becomes an
O(log n) index scan.
Changes:
- drizzle/0013_api_key_hash_index.sql: CREATE UNIQUE INDEX CONCURRENTLY
so the migration is safe on a live database (no table lock)
- src/db/schema.ts: add uniqueIndex('idx_publishers_api_key_hash') so
Drizzle's schema matches the database
|
@wendyamoni-creator is attempting to deploy a commit to the work Team on Vercel. A member of the Team first needs to authorize it. |
…e agent) - src/db/schema.ts: merged [markers] — model resolved the conflict markers Co-authored-by: Simple Agent <agent@simple.dev>
|
@wendyamoni-creator Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
victorisiguzoruzoma874
merged commit Oct 19, 2026
2b9509e
into
SynapsVault:main
0 of 3 checks passed
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
Closes #41.
Every authenticated request to the API runs
SELECT … FROM publishers WHERE api_key_hash = $1. Without an index this is a sequential scan that grows with the publisher count. This PR adds a unique index so the lookup is always an index scan.Changes
drizzle/0013_api_key_hash_index.sqlCREATE UNIQUE INDEX CONCURRENTLYonapi_key_hashsrc/db/schema.tsuniqueIndex('idx_publishers_api_key_hash')added to publishers table definitionMigration safety
The migration uses
CONCURRENTLYso it builds the index without holding an exclusive lock on the table. It is safe to apply against a live database with active traffic.IF NOT EXISTSmakes it idempotent.Why unique?
api_key_hashis a SHA-256 digest of the plaintext key. No two keys should produce the same hash; enforcing this at the DB level is a free correctness guarantee on top of the performance win.Acceptance criteria
CONCURRENTLY IF NOT EXISTS)EXPLAINonSELECT … WHERE api_key_hash = $1will showIndex Scan using idx_publishers_api_key_hashcloses Index publishers.api_key_hash, since every authenticated request scans the table #41