Небольшие улучшения

This commit is contained in:
Book Pauk
2022-10-31 13:35:59 +07:00
parent c5bd31e514
commit 6e9662b409

View File

@@ -304,7 +304,7 @@ class DbSearcher {
const table = `${from}_id`;
await db.open({table});
const rows = await db.select({table});
let rows = await db.select({table});
await db.close({table});
for (const row of rows) {
@@ -319,6 +319,10 @@ class DbSearcher {
this.bookIdMap[from] = map;
rows = null;
await db.freeMemory();
utils.freeMemory();
return this.bookIdMap[from];
} finally {
this.lock.ret();
@@ -380,16 +384,28 @@ class DbSearcher {
if (bookIds) {
const tableIdsSet = new Set();
const bookIdMap = await this.fillBookIdMap(from);
let proc = 0;
let nextProc = 0;
for (const bookId of bookIds) {
const tableIdValue = bookIdMap.get(bookId);
if (!tableIdValue)
continue;
if (Array.isArray(tableIdValue)) {
for (const tableId of tableIdValue)
for (const tableId of tableIdValue) {
tableIdsSet.add(tableId);
} else
proc++;
}
} else {
tableIdsSet.add(tableIdValue);
proc++;
}
//прерываемся иногда, чтобы не блокировать Event Loop
if (proc >= nextProc) {
nextProc += 10000;
await utils.processLoop();
}
}
tableIds = Array.from(tableIdsSet);