improve xatab scrap performance and update seed with xatab repacks

This commit is contained in:
Zamitto 2024-05-17 16:59:16 -03:00
parent b330c94dca
commit 5908544602
2 changed files with 33 additions and 19 deletions

BIN
hydra.db

Binary file not shown.

View File

@ -12,6 +12,9 @@ import { formatBytes } from "@shared";
import { getFileBuffer } from "@main/helpers"; import { getFileBuffer } from "@main/helpers";
const worker = createWorker({}); const worker = createWorker({});
worker.setMaxListeners(11);
let totalPages = 1;
const formatXatabDate = (str: string) => { const formatXatabDate = (str: string) => {
const date = new Date(); const date = new Date();
@ -69,12 +72,19 @@ export const getNewRepacksFromXatab = async (
const repacks: QueryDeepPartialEntity<Repack>[] = []; const repacks: QueryDeepPartialEntity<Repack>[] = [];
for (const $a of Array.from( if (page === 1) {
window.document.querySelectorAll(".entry__title a") totalPages = Number(
)) { window.document.querySelector(
try { "#bottom-nav > div.pagination > a:nth-child(12)"
const repack = await getXatabRepack(($a as HTMLAnchorElement).href); )?.textContent
);
}
const repacksFromPage = Array.from(
window.document.querySelectorAll(".entry__title a")
).map(($a) => {
return getXatabRepack(($a as HTMLAnchorElement).href)
.then((repack) => {
if (repack) { if (repack) {
repacks.push({ repacks.push({
title: $a.textContent!, title: $a.textContent!,
@ -83,12 +93,15 @@ export const getNewRepacksFromXatab = async (
page, page,
}); });
} }
} catch (err: unknown) { })
.catch((err: unknown) => {
logger.error((err as Error).message, { logger.error((err as Error).message, {
method: "getNewRepacksFromXatab", method: "getNewRepacksFromXatab",
}); });
} });
} });
await Promise.all(repacksFromPage);
const newRepacks = repacks.filter( const newRepacks = repacks.filter(
(repack) => (repack) =>
@ -98,6 +111,7 @@ export const getNewRepacksFromXatab = async (
); );
if (!newRepacks.length) return; if (!newRepacks.length) return;
if (page === totalPages) return;
await savePage(newRepacks); await savePage(newRepacks);