Browse Source

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

Book Pauk 2 years ago
parent
commit
6e9662b409
1 changed files with 19 additions and 3 deletions
  1. 19 3
      server/core/DbSearcher.js

+ 19 - 3
server/core/DbSearcher.js

@@ -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);