fix: removing repacks from worker threads to fix race condition

This commit is contained in:
Chubby Granny Chaser
2024-06-03 23:09:47 +01:00
parent 4559e23610
commit ea923d5082
13 changed files with 71 additions and 105 deletions

View File

@@ -1,6 +1,5 @@
import path from "node:path";
import steamGamesWorkerPath from "./steam-games.worker?modulePath";
import repacksWorkerPath from "./repacks.worker?modulePath";
import downloadSourceWorkerPath from "./download-source.worker?modulePath";
import Piscina from "piscina";
@@ -14,10 +13,6 @@ export const steamGamesWorker = new Piscina({
},
});
export const repacksWorker = new Piscina({
filename: repacksWorkerPath,
});
export const downloadSourceWorker = new Piscina({
filename: downloadSourceWorkerPath,
});

View File

@@ -1,37 +0,0 @@
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[]) => {
for (let i = 0; i < state.repacks.length; i++) {
repacksIndex.remove(i);
}
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, query: formatName(options.query ?? "") })
.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 };
});
};