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 { import {
index,
pgEnum, pgEnum,
pgTable, pgTable,
text, text,
@@ -48,5 +49,6 @@ export const communitySuggestions = pgTable(
table.fieldName, table.fieldName,
table.userId, table.userId,
), ),
index("suggestions_status_idx").on(table.status),
], ],
) )
+5 -1
View File
@@ -1,5 +1,6 @@
import { import {
boolean, boolean,
index,
pgTable, pgTable,
text, text,
timestamp, timestamp,
@@ -21,5 +22,8 @@ export const gameVersions = pgTable(
isLatest: boolean("is_latest").default(false).notNull(), isLatest: boolean("is_latest").default(false).notNull(),
createdAt: timestamp("created_at").defaultNow().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(), createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_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_hardware_upscaler_idx").on(table.hardwareSlug, table.upscalerType),
index("perf_version_idx").on(table.versionId), index("perf_version_idx").on(table.versionId),
index("perf_user_idx").on(table.userId), 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 { import {
index,
text, text,
pgEnum, pgEnum,
pgTable, pgTable,
@@ -37,4 +38,5 @@ export const reports = pgTable("reports", {
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp("created_at").defaultNow().notNull(),
}, (table) => [ }, (table) => [
uniqueIndex("reports_entry_reporter_unique").on(table.entryId, table.reporterId), uniqueIndex("reports_entry_reporter_unique").on(table.entryId, table.reporterId),
index("reports_status_idx").on(table.status),
]) ])