MCPcopy Create free account
hub / github.com/alexankitty/Myrient-Search-Engine / getAllFiles

Function getAllFiles

lib/crawler/dircrawl.js:16–149  ·  view source on GitHub ↗
(catList)

Source from the content-addressed store, hash-verified

14const BATCH_SIZE = 1000; // Process files in batches for better performance
15
16export default async function getAllFiles(catList) {
17 var proctime = new Timer();
18 const url = "https://myrient.erista.me/files/";
19 let parentRows = await getTableRows({ url: url, base: "" });
20 let parents = [];
21 for (let x = 0; x < parentRows.html.length; x++) {
22 parents.push(
23 await parseOutFile({
24 file: parentRows.html[x],
25 base: "",
26 url: url,
27 catList: catList,
28 })
29 );
30 }
31 let dirWork = splitFilesAndFolders(parents);
32 // First run should only have directories. Is there a reason this could change in the future?
33 let dirs = dirWork.directories;
34 let fetchTasks = [];
35 let resolvedFetchTasks = [];
36 let parseTasks = [];
37 let fileCount = 0;
38 let currentBatch = [];
39
40 while (
41 dirs.length > 0 ||
42 fetchTasks.length > 0 ||
43 parseTasks.length > 0 ||
44 resolvedFetchTasks.length > 0
45 ) {
46 let dirStatus = "";
47 if (dirs.length > 0) {
48 debugPrint(`Queueing: ${dirs[0].name}`);
49 fetchTasks.push(
50 piscina
51 .run(
52 { url: dirs[0].path, base: dirs[0].name },
53 { name: "getTableRows" }
54 )
55 .catch((err) => {
56 console.error(err);
57 })
58 );
59 dirs.shift();
60 }
61
62 if (
63 fetchTasks.length >= parseInt(process.env.MAX_FETCH_JOBS) ||
64 ((fetchTasks.length > 0 || resolvedFetchTasks.length > 0) &&
65 parseTasks.length == 0)
66 ) {
67 debugPrint(`Resolving ${fetchTasks.length} fetch tasks.`);
68 let settledTasks = await Promise.all(fetchTasks);
69 resolvedFetchTasks.push(...settledTasks);
70 while (resolvedFetchTasks.length > 0) {
71 if (piscina.queueSize >= parseInt(process.env.MAX_JOB_QUEUE)) {
72 break;
73 }

Callers 1

getFilesJobFunction · 0.85

Calls 7

elapsedMethod · 0.95
getTableRowsFunction · 0.90
parseOutFileFunction · 0.90
splitFilesAndFoldersFunction · 0.85
debugPrintFunction · 0.85
processBatchFunction · 0.85
singleLineStatusFunction · 0.70

Tested by

no test coverage detected