mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 06:41:03 +00:00
feat: migrating repacks to a worker
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import path from "node:path";
|
||||
import steamGamesWorkerPath from "./steam-games.worker?modulePath";
|
||||
import repacksWorkerPath from "./repacks.worker?modulePath";
|
||||
|
||||
import Piscina from "piscina";
|
||||
|
||||
@@ -11,3 +12,7 @@ export const steamGamesWorker = new Piscina({
|
||||
steamGamesPath: path.join(seedsPath, "steam-games.json"),
|
||||
},
|
||||
});
|
||||
|
||||
export const repacksWorker = new Piscina({
|
||||
filename: repacksWorkerPath,
|
||||
});
|
||||
|
||||
31
src/main/workers/repacks.worker.ts
Normal file
31
src/main/workers/repacks.worker.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { formatName } from "@shared";
|
||||
import { CatalogueEntry, GameRepack } from "@types";
|
||||
import flexSearch from "flexsearch";
|
||||
|
||||
const repacksIndex = new flexSearch.Index();
|
||||
|
||||
const state: { repacks: GameRepack[] } = { repacks: [] };
|
||||
|
||||
export const setRepacks = (repacks: GameRepack[]) => {
|
||||
state.repacks = repacks;
|
||||
|
||||
for (let i = 0; i < repacks.length; i++) {
|
||||
const repack = repacks[i];
|
||||
|
||||
const formattedTitle = formatName(repack.title);
|
||||
|
||||
repacksIndex.add(i, formattedTitle);
|
||||
}
|
||||
};
|
||||
|
||||
export const search = (options: flexSearch.SearchOptions) =>
|
||||
repacksIndex.search(options).map((index) => state.repacks[index]);
|
||||
|
||||
export const list = () => state.repacks;
|
||||
|
||||
export const findRepacksForCatalogueEntries = (entries: CatalogueEntry[]) => {
|
||||
return entries.map((entry) => {
|
||||
const repacks = search({ query: formatName(entry.title) });
|
||||
return { ...entry, repacks };
|
||||
});
|
||||
};
|
||||
@@ -25,7 +25,7 @@ for (let i = 0; i < steamGames.length; i++) {
|
||||
}
|
||||
|
||||
export const search = (options: flexSearch.SearchOptions) => {
|
||||
const results = steamGamesIndex.search(options.query ?? "", options);
|
||||
const results = steamGamesIndex.search(options);
|
||||
const games = results.map((index) => steamGames[index]);
|
||||
|
||||
return orderBy(games, ["name"], ["asc"]);
|
||||
|
||||
Reference in New Issue
Block a user