Улучшена отзывчивость поисковика при старте

This commit is contained in:
Book Pauk
2022-10-31 13:21:10 +07:00
parent ea5cf4e3bd
commit c5bd31e514

View File

@@ -1,4 +1,5 @@
//const _ = require('lodash'); //const _ = require('lodash');
const LockQueue = require('./LockQueue');
const utils = require('./utils'); const utils = require('./utils');
const maxMemCacheSize = 100; const maxMemCacheSize = 100;
@@ -15,6 +16,7 @@ class DbSearcher {
this.config = config; this.config = config;
this.db = db; this.db = db;
this.lock = new LockQueue();
this.searchFlag = 0; this.searchFlag = 0;
this.timer = null; this.timer = null;
this.closed = false; this.closed = false;
@@ -23,6 +25,7 @@ class DbSearcher {
this.bookIdMap = {}; this.bookIdMap = {};
this.periodicCleanCache();//no await this.periodicCleanCache();//no await
this.fillBookIdMapAll();//no await
} }
queryKey(q) { queryKey(q) {
@@ -291,7 +294,11 @@ class DbSearcher {
} }
async fillBookIdMap(from) { 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 db = this.db;
const map = new Map(); const map = new Map();
const table = `${from}_id`; const table = `${from}_id`;
@@ -311,8 +318,17 @@ class DbSearcher {
} }
this.bookIdMap[from] = map; 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) { async filterTableIds(tableIds, from, query) {