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

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