From fe0f272accc1368423be88618d6bb1d5e9245f47 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 2 Oct 2022 15:54:40 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B8=D0=BE=D0=B4=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20inpx=20=D0=B4=D0=BB=D1=8F=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B7=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config/base.js | 1 + server/config/index.js | 1 + server/core/WebWorker.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/server/config/base.js b/server/config/base.js index c3af3f8..d36123c 100644 --- a/server/config/base.js +++ b/server/config/base.js @@ -22,6 +22,7 @@ module.exports = { maxFilesDirSize: 1024*1024*1024,//1Gb queryCacheEnabled: true, cacheCleanInterval: 60,//minutes + inpxCheckInterval: 60,//minutes lowMemoryMode: false, webConfigParams: ['name', 'version', 'branch', 'bookReadLink'], diff --git a/server/config/index.js b/server/config/index.js index 42b4953..1422c31 100644 --- a/server/config/index.js +++ b/server/config/index.js @@ -10,6 +10,7 @@ const propsToSave = [ 'maxFilesDirSize', 'queryCacheEnabled', 'cacheCleanInterval', + 'inpxCheckInterval', 'lowMemoryMode', 'server', ]; diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index fcd61f2..06206c9 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -53,7 +53,9 @@ class WebWorker { maxSize: this.config.maxFilesDirSize, }, ]; + this.periodicCleanDir(dirConfig);//no await + this.periodicCheckInpx();//no await instance = this; } @@ -489,6 +491,35 @@ class WebWorker { ayncExit.exit(1); } } + + async periodicCheckInpx() { + const inpxCheckInterval = this.config.inpxCheckInterval; + if (!inpxCheckInterval) + return; + + while (1) {// eslint-disable-line no-constant-condition + try { + while (this.myState != ssNormal) + await utils.sleep(1000); + + log('check inpx file for changes'); + const newInpxHash = await utils.getFileHash(this.config.inpxFile, 'sha256', 'hex'); + + const dbConfig = await this.dbConfig(); + const currentInpxHash = (dbConfig.inpxHash ? dbConfig.inpxHash : ''); + + if (newInpxHash !== currentInpxHash) { + log('inpx file changed, recreating DB'); + await this.recreateDb(); + } + } catch(e) { + log(LM_ERR, `periodicCheckInpx: ${e.message}`); + } + + //await utils.sleep(inpxCheckInterval*60*1000); + await utils.sleep(10000); + } + } } module.exports = WebWorker; \ No newline at end of file