perf: improving get-random-game performance

This commit is contained in:
Chubby Granny Chaser 2024-06-03 16:56:12 +01:00
parent 467ea29ec2
commit c6242fa3e1
No known key found for this signature in database
2 changed files with 5 additions and 8 deletions

View file

@ -5,8 +5,6 @@ import { getSteam250List } from "@main/services";
import { registerEvent } from "../register-event"; import { registerEvent } from "../register-event";
import { searchSteamGames } from "../helpers/search-games"; import { searchSteamGames } from "../helpers/search-games";
import type { Steam250Game } from "@types"; import type { Steam250Game } from "@types";
import { repacksWorker } from "@main/workers";
import { formatName } from "@shared";
const state = { games: Array<Steam250Game>(), index: 0 }; const state = { games: Array<Steam250Game>(), index: 0 };
@ -17,12 +15,9 @@ const filterGames = async (games: Steam250Game[]) => {
const catalogue = await searchSteamGames({ query: game.title }); const catalogue = await searchSteamGames({ query: game.title });
if (catalogue.length) { if (catalogue.length) {
const repacks = await repacksWorker.run( const [steamGame] = catalogue;
{ query: formatName(catalogue[0].title) },
{ name: "search" }
);
if (repacks.length) { if (steamGame.repacks.length) {
results.push(game); results.push(game);
} }
} }

View file

@ -23,7 +23,9 @@ export const setRepacks = (repacks: GameRepack[]) => {
}; };
export const search = (options: flexSearch.SearchOptions) => export const search = (options: flexSearch.SearchOptions) =>
repacksIndex.search(options).map((index) => state.repacks[index]); repacksIndex
.search({ ...options, query: formatName(options.query ?? "") })
.map((index) => state.repacks[index]);
export const list = () => state.repacks; export const list = () => state.repacks;