Skip to content

Commit b10055b

Browse files
committed
perf(database): index PersonalAccessToken.userId so token lookups stop seq-scanning
Both PAT-by-user lookups (userId + revokedAt is null, and userId + name) had no index on userId and seq-scanned the whole table, reading ~44k-47k rows to return ~1. userId is also an unindexed foreign key. Add @@index ([userId]); a user owns few PATs so the single-column index serves both query shapes. Seeded local EXPLAIN (50k rows): Seq Scan -> Index Scan on both queries, shared buffers 689 pages -> 3.
1 parent 7b7d489 commit b10055b

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: improvement
4+
---
5+
6+
Speed up personal access token lookups by indexing them on their owner
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "PersonalAccessToken_userId_idx" ON "public"."PersonalAccessToken"("userId");

internal-packages/database/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ model PersonalAccessToken {
155155
updatedAt DateTime @updatedAt
156156
157157
authorizationCodes AuthorizationCode[]
158+
159+
@@index([userId])
158160
}
159161

160162
enum OrganizationAccessTokenType {

0 commit comments

Comments
 (0)