feat: add database indexes for frequent query patterns

This commit is contained in:
2026-05-16 16:57:23 +08:00
parent 6737761151
commit 3388bf42b5
5 changed files with 15 additions and 2 deletions
+2
View File
@@ -1,4 +1,5 @@
import {
index,
pgEnum,
pgTable,
text,
@@ -48,5 +49,6 @@ export const communitySuggestions = pgTable(
table.fieldName,
table.userId,
),
index("suggestions_status_idx").on(table.status),
],
)
+5 -1
View File
@@ -1,5 +1,6 @@
import {
boolean,
index,
pgTable,
text,
timestamp,
@@ -21,5 +22,8 @@ export const gameVersions = pgTable(
isLatest: boolean("is_latest").default(false).notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
},
(table) => [unique("game_build_unique").on(table.gameId, table.buildId)]
(table) => [
unique("game_build_unique").on(table.gameId, table.buildId),
index("perf_game_lookup_idx").on(table.gameId),
]
)
+4 -1
View File
@@ -97,5 +97,8 @@ export const games = pgTable(
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
},
(table) => [index("games_source_idx").on(table.source)],
(table) => [
index("games_source_idx").on(table.source),
index("games_sync_status_idx").on(table.syncStatus, table.steamAppId),
],
)
+2
View File
@@ -112,5 +112,7 @@ export const performanceEntries = pgTable(
index("perf_hardware_upscaler_idx").on(table.hardwareSlug, table.upscalerType),
index("perf_version_idx").on(table.versionId),
index("perf_user_idx").on(table.userId),
index("perf_removed_created_idx").on(table.isRemoved, table.createdAt.desc()),
index("perf_upvotes_idx").on(table.upvotes.desc()),
],
)
+2
View File
@@ -1,4 +1,5 @@
import {
index,
text,
pgEnum,
pgTable,
@@ -37,4 +38,5 @@ export const reports = pgTable("reports", {
createdAt: timestamp("created_at").defaultNow().notNull(),
}, (table) => [
uniqueIndex("reports_entry_reporter_unique").on(table.entryId, table.reporterId),
index("reports_status_idx").on(table.status),
])