Skip to content

Commit

Permalink
improve clarity and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
otobot1 committed Aug 26, 2024
1 parent d346bc8 commit 4278b7e
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/server/api/routers/map_mod_publisher/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,34 @@ const getModSearchDatabaseInfoForAllMods = async (mods: TrimmedMod[]): Promise<T
const modSearchDatabase = await getCurrentModSearchDatabase();


outerLoop: for (const mod of mods) {
for (const modSearchDatabaseMod of modSearchDatabase) {
if (mod.gamebananaModId === modSearchDatabaseMod.GameBananaId) {
mod.Screenshots = modSearchDatabaseMod.Screenshots;
mod.Files = modSearchDatabaseMod.Files;
continue outerLoop;
const modSearchDatabaseTuples: [number, ModSearchDatabase_ModInfo][] = modSearchDatabase.map((modSearchDatabaseMod) => [modSearchDatabaseMod.GameBananaId, modSearchDatabaseMod]);

const modSearchDatabaseMap = new Map<number, ModSearchDatabase_ModInfo>(modSearchDatabaseTuples);


const modsWithModSearchDatabaseInfo = mods.map(
(mod) => {
const modSearchDatabaseMod = modSearchDatabaseMap.get(mod.gamebananaModId);


if (modSearchDatabaseMod) {
return {
...mod,
Screenshots: modSearchDatabaseMod.Screenshots,
Files: modSearchDatabaseMod.Files,
};
}
}

// if the mod is not found in the mod search database, log a warning
console.warn(`Mod with gamebananaModId ${mod.gamebananaModId} not found in mod search database`);
}

// if the mod is not found in the mod search database, log a warning
console.warn(`Mod with gamebananaModId ${mod.gamebananaModId} not found in mod search database`);

return mod;
}
);


return mods;
return modsWithModSearchDatabaseInfo;
};


Expand Down

0 comments on commit 4278b7e

Please sign in to comment.