Jelajahi Sumber

Мелкий рефакторинг

Book Pauk 2 tahun lalu
induk
melakukan
7a58b5a3ba
1 mengubah file dengan 16 tambahan dan 18 penghapusan
  1. 16 18
      server/core/DbCreator.js

+ 16 - 18
server/core/DbCreator.js

@@ -462,11 +462,7 @@ class DbCreator {
             titleRec.id = ++id;
         }
 
-        //config
-        await db.create({
-            table: 'config'
-        });
-
+        //stats
         const stats = {
             filesCount: 0,
             recsLoaded,
@@ -483,14 +479,6 @@ class DbCreator {
         };
         //console.log(stats);
 
-        const inpxHashCreator = new InpxHashCreator(config);
-
-        await db.insert({table: 'config', rows: [
-            {id: 'inpxInfo', value: (inpxFilter && inpxFilter.info ? inpxFilter.info : parser.info)},
-            {id: 'stats', value: stats},
-            {id: 'inpxHash', value: await inpxHashCreator.getHash()},
-        ]});
-
         //сохраним поисковые таблицы
         const chunkSize = 10000;
 
@@ -577,6 +565,19 @@ class DbCreator {
         await db.freeMemory();
         utils.freeMemory();
 
+        //config сохраняем в самом конце, нет конфига - с базой что-то не так
+        const inpxHashCreator = new InpxHashCreator(config);
+
+        await db.create({
+            table: 'config'
+        });
+
+        await db.insert({table: 'config', rows: [
+            {id: 'inpxInfo', value: (inpxFilter && inpxFilter.info ? inpxFilter.info : parser.info)},
+            {id: 'stats', value: stats},
+            {id: 'inpxHash', value: await inpxHashCreator.getHash()},
+        ]});
+
         callback({job: 'done', jobMessage: ''});
     }
 
@@ -689,12 +690,9 @@ class DbCreator {
             });
         `});
 
-        if (countRes.length) {
+        if (countRes.length)
             stats.filesCount = countRes[0].count;
-            await db.insert({table: 'config', replace: true, rows: [
-                {id: 'stats', value: stats},
-            ]});
-        }
+
         countDone = true;
     }
 }