From c5bd31e514e92a43136b7dc3f3b1001fba5cc331 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 31 Oct 2022 13:21:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D1=82=D0=B7=D1=8B=D0=B2=D1=87=D0=B8=D0=B2=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/DbSearcher.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index 7bde3f5..3de34b7 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -1,4 +1,5 @@ //const _ = require('lodash'); +const LockQueue = require('./LockQueue'); const utils = require('./utils'); const maxMemCacheSize = 100; @@ -15,6 +16,7 @@ class DbSearcher { this.config = config; this.db = db; + this.lock = new LockQueue(); this.searchFlag = 0; this.timer = null; this.closed = false; @@ -23,6 +25,7 @@ class DbSearcher { this.bookIdMap = {}; this.periodicCleanCache();//no await + this.fillBookIdMapAll();//no await } queryKey(q) { @@ -291,7 +294,11 @@ class DbSearcher { } async fillBookIdMap(from) { - if (!this.bookIdMap[from]) { + if (this.bookIdMap[from]) + return this.bookIdMap[from]; + + await this.lock.get(); + try { const db = this.db; const map = new Map(); const table = `${from}_id`; @@ -311,8 +318,17 @@ class DbSearcher { } this.bookIdMap[from] = map; + + return this.bookIdMap[from]; + } finally { + this.lock.ret(); } - return this.bookIdMap[from]; + } + + async fillBookIdMapAll() { + await this.fillBookIdMap('author'); + await this.fillBookIdMap('series'); + await this.fillBookIdMap('title'); } async filterTableIds(tableIds, from, query) {