From ba3d6adac690a6711f292585538474cdb68a5efc Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 20 Oct 2022 18:03:47 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D1=85=D0=B2=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20inp?= =?UTF-8?q?x-=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/WebWorker.js | 34 ++++++++++++++++++++++++++++------ server/index.js | 2 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index a34a500..58dac7a 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -5,7 +5,7 @@ const _ = require('lodash'); const ZipReader = require('./ZipReader'); const WorkerState = require('./WorkerState');//singleton -const { JembaDbThread } = require('jembadb'); +const { JembaDb, JembaDbThread } = require('jembadb'); const DbCreator = require('./DbCreator'); const DbSearcher = require('./DbSearcher'); const InpxHashCreator = require('./InpxHashCreator'); @@ -141,10 +141,33 @@ class WebWorker { this.inpxFileHash = await this.inpxHashCreator.getInpxFileHash(); - //пересоздаем БД из INPX если нужно + //проверим полный InxpHash (включая фильтр и версию БД) + //для этого заглянем в конфиг внутри БД, если он есть + if (!(config.recreateDb || recreate) && await fs.pathExists(dbPath)) { + const newInpxHash = await this.inpxHashCreator.getHash(); + + const tmpDb = new JembaDb(); + await tmpDb.lock({dbPath, softLock: true}); + + try { + await tmpDb.open({table: 'config'}); + const rows = await tmpDb.select({table: 'config', where: `@@id('inpxHash')`}); + + if (!rows.length || newInpxHash !== rows[0].value) + throw new Error('inpx file: changes found on start, recreating DB'); + } catch (e) { + log(LM_WARN, e.message); + recreate = true; + } finally { + await tmpDb.unlock(); + } + } + + //удалим БД если нужно if (config.recreateDb || recreate) await fs.remove(dbPath); + //пересоздаем БД из INPX если нужно if (!await fs.pathExists(dbPath)) { try { await this.createDb(dbPath); @@ -160,7 +183,7 @@ class WebWorker { this.setMyState(ssDbLoading); log('Searcher DB loading'); - const db = new JembaDbThread(); + const db = new JembaDbThread();//в отдельном потоке await db.lock({ dbPath, softLock: true, @@ -181,14 +204,13 @@ class WebWorker { db.wwCache = {}; this.db = db; - log('Searcher DB ready'); + this.setMyState(ssNormal); + log('Searcher DB ready'); this.logServerStats(); } catch (e) { log(LM_FATAL, e.message); ayncExit.exit(1); - } finally { - this.setMyState(ssNormal); } } diff --git a/server/index.js b/server/index.js index bcf3442..4d26301 100644 --- a/server/index.js +++ b/server/index.js @@ -114,7 +114,7 @@ async function init() { } } } else { - config.inpxFile = `${config.tempDir}/${utils.randomHexString(20)}`; + config.inpxFile = `${config.dataDir}/remote.inpx`; const RemoteLib = require('./core/RemoteLib');//singleton const remoteLib = new RemoteLib(config); await remoteLib.downloadInpxFile();