From 91cafc05d22a5550642c464f66d16630592d63bb Mon Sep 17 00:00:00 2001 From: zkldi Date: Mon, 10 May 2021 04:43:59 +0100 Subject: [PATCH] generify song/charts indexes --- server/scripts/set-indexes.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server/scripts/set-indexes.ts b/server/scripts/set-indexes.ts index 6aa933a8b..ddb324787 100644 --- a/server/scripts/set-indexes.ts +++ b/server/scripts/set-indexes.ts @@ -2,7 +2,8 @@ import monk from "monk"; import { Command } from "commander"; import CreateLogCtx from "../src/logger"; import { IndexOptions } from "mongodb"; -import { ValidDatabases } from "kamaitachi-common"; +import { ValidDatabases, Game } from "kamaitachi-common"; +import { supportedGames } from "kamaitachi-common/js/config"; const logger = CreateLogCtx("set-indexes.ts"); @@ -36,11 +37,6 @@ const indexes: Partial> = { index({ chartID: 1, userID: 1 }, UNIQUE), index({ chartID: 1, "scoreData.percent": 1 }), ], - "charts-iidx": [ - index({ chartID: 1 }, UNIQUE), - index({ songID: 1, difficulty: 1, playtype: 1, isPrimary: 1 }, UNIQUE), - ], - "songs-iidx": [index({ id: 1 }, UNIQUE), index({ title: 1 })], sessions: [ // lol index({ timeStarted: 1, timeEnded: 1, userID: 1, game: 1, playtype: 1 }), @@ -62,6 +58,15 @@ const indexes: Partial> = { ], }; +for (const game of supportedGames) { + indexes[`charts-${game}` as "charts-iidx"] = [ + index({ chartID: 1 }, UNIQUE), + index({ songID: 1, difficulty: 1, playtype: 1, isPrimary: 1 }, UNIQUE), + ]; + + indexes[`songs-${game}` as "songs-iidx"] = [index({ id: 1 }, UNIQUE), index({ title: 1 })]; +} + (async () => { logger.info(`Starting indexing for ${options.db ?? "ktblackdb"}...`);