From 6e9662b40905c67d2fedcb225c072985eb126c1d Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 31 Oct 2022 13:35:59 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/DbSearcher.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index 3de34b7..b198f59 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -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);