Skip to content

Commit d8145db

Browse files
committed
perf(database): index PersonalAccessToken.userId so lookups stop seq-scanning
The two personal-access-token lookups filtered by userId (one also filtering revokedAt, the other also filtering name) had no index on userId, so each seq-scanned the whole table to return a single row. userId is also an unindexed foreign key. Add @@index([userId]); a user owns few PATs, so the single-column index serves both query shapes without needing a composite. Migration uses CREATE INDEX CONCURRENTLY IF NOT EXISTS.
1 parent 7b7d489 commit d8145db

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)