Skip to content

perf: unique index on publishers.api_key_hash (#41) - #143

Merged
victorisiguzoruzoma874 merged 2 commits into
SynapsVault:mainfrom
wendyamoni-creator:feat/api-key-hash-index-41
Oct 19, 2026
Merged

victorisiguzoruzoma874 merged 2 commits into
SynapsVault:mainfrom
wendyamoni-creator:feat/api-key-hash-index-41

Conversation

@wendyamoni-creator

@wendyamoni-creator wendyamoni-creator commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

File Change
drizzle/0013_api_key_hash_index.sql CREATE UNIQUE INDEX CONCURRENTLY on api_key_hash
src/db/schema.ts uniqueIndex('idx_publishers_api_key_hash') added to publishers table definition

Migration safety

The migration uses CONCURRENTLY so 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 EXISTS makes it idempotent.

Why unique?

api_key_hash is 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

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
@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@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>
@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@victorisiguzoruzoma874
victorisiguzoruzoma874 merged commit 2b9509e into SynapsVault:main Oct 19, 2026
0 of 3 checks passed
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.

Index publishers.api_key_hash, since every authenticated request scans the table

2 participants