Работа над проектом

This commit is contained in:
Book Pauk
2022-08-21 21:10:56 +07:00
parent c7073635e3
commit 705fce73f7
7 changed files with 172 additions and 28 deletions

View File

@@ -193,7 +193,7 @@ class DbSearcher {
//сначала попробуем найти в кеше
const q = query;
const keyArr = [q.author, q.series, q.title, q.genre, q.lang];
const keyStr = keyArr.join('');
const keyStr = `query-${keyArr.join('')}`;
if (!keyStr) {//пустой запрос
if (db.searchCache.authorIdsAll)
@@ -262,6 +262,42 @@ class DbSearcher {
}
}
async getBookList(authorId) {
if (this.closed)
throw new Error('DbSearcher closed');
this.searchFlag++;
try {
const db = this.db;
//выборка автора по authorId
const rows = await db.select({
table: 'author',
map: `(r) => ({author: r.author, bookId: r.bookId})`,
where: `@@id(${db.esc(authorId)})`
});
let author = '';
let result = [];
if (rows.length) {
author = rows[0].author;
//выборка книг по bookId
result = await db.select({
table: 'book',
//map: `(r) => ({})`,
where: `@@id(${db.esc(rows[0].bookId)})`,
});
}
return {author, books: result};
} finally {
this.searchFlag--;
}
}
async periodicCleanCache() {
this.timer = null;
const cleanInterval = 5*1000;//this.config.cacheCleanInterval*60*1000;