Răsfoiți Sursa

Рефакторинг

Book Pauk 2 ani în urmă
părinte
comite
88d49852e0
1 a modificat fișierele cu 11 adăugiri și 11 ștergeri
  1. 11 11
      server/core/DbSearcher.js

+ 11 - 11
server/core/DbSearcher.js

@@ -55,7 +55,7 @@ class DbSearcher {
     async selectAuthorIds(query) {
         const db = this.db;
 
-        let authorIds = new Set();
+        let authorIds = [];
 
         //сначала выберем все id авторов по фильтру
         //порядок id соответсвует ASC-сортировке по author
@@ -69,7 +69,7 @@ class DbSearcher {
             });
 
             for (const row of authorRows)
-                authorIds.add(row.id);
+                authorIds.push(row.id);
         } else {//все авторы
             if (!db.searchCache.authorIdsAll) {
                 const authorRows = await db.select({
@@ -77,18 +77,17 @@ class DbSearcher {
                     dirtyIdsOnly: true,
                 });
 
-                db.searchCache.authorIdsAll = [];
                 for (const row of authorRows) {
-                    authorIds.add(row.id);
-                    db.searchCache.authorIdsAll.push(row.id);
+                    authorIds.push(row.id);
                 }
+
+                db.searchCache.authorIdsAll = authorIds;
             } else {//оптимизация
-                authorIds = new Set(db.searchCache.authorIdsAll);
+                authorIds = db.searchCache.authorIdsAll;
             }
         }
 
         const idsArr = [];
-        idsArr.push(authorIds);
 
         //серии
         if (query.series && query.series !== '*') {
@@ -176,12 +175,13 @@ class DbSearcher {
             idsArr.push(ids);
         }
 
-        if (idsArr.length > 1)
-            authorIds = utils.intersectSet(idsArr);
+        if (idsArr.length) {
+            //ищем пересечение множеств
+            idsArr.push(new Set(authorIds));
+            authorIds = Array.from(utils.intersectSet(idsArr));
+        }
 
         //сортировка
-        authorIds = Array.from(authorIds);
-        
         authorIds.sort((a, b) => a - b);
 
         return authorIds;