Убрал лишнее кеширование

This commit is contained in:
Book Pauk
2022-10-10 20:57:30 +07:00
parent 7cf5e91cc4
commit 09b7c38348

View File

@@ -263,26 +263,6 @@ class DbSearcher {
}
}
async selectBookList(authorId) {
const db = this.db;
//выборка автора по authorId
const rows = await db.select({
table: 'author_book',
where: `@@id(${db.esc(authorId)})`
});
let author = '';
let books = '';
if (rows.length) {
author = rows[0].author;
books = rows[0].books;
}
return {author, books};
}
async getBookList(authorId) {
if (this.closed)
throw new Error('DbSearcher closed');
@@ -292,66 +272,26 @@ class DbSearcher {
try {
const db = this.db;
let result;
//выборка автора по authorId
const rows = await db.select({
table: 'author_book',
where: `@@id(${db.esc(authorId)})`
});
if (this.config.queryCacheEnabled) {
const key = `author_books-${authorId}`;
const rows = await db.select({table: 'query_cache', where: `@@id(${db.esc(key)})`});
let author = '';
let books = '';
if (rows.length) {//нашли в кеше
await db.insert({
table: 'query_time',
replace: true,
rows: [{id: key, time: Date.now()}],
});
result = rows[0].value;
} else {//не нашли в кеше
result = await this.selectBookList(authorId);
//кладем в кеш
await db.insert({
table: 'query_cache',
replace: true,
rows: [{id: key, value: result}],
});
await db.insert({
table: 'query_time',
replace: true,
rows: [{id: key, time: Date.now()}],
});
}
} else {
result = await this.selectBookList(authorId);
if (rows.length) {
author = rows[0].author;
books = rows[0].books;
}
return result;
return {author, books};
} finally {
this.searchFlag--;
}
}
async selectSeriesBookList(seriesId) {
const db = this.db;
//выборка серии по seriesId
const rows = await db.select({
table: 'series',
where: `@@id(${db.esc(seriesId)})`
});
let books = [];
if (rows.length) {
books = await db.select({
table: 'book',
where: `@@id(${db.esc(rows[0].bookId)})`
});
}
return {books: JSON.stringify(books)};
}
async getSeriesBookList(seriesId) {
if (this.closed)
throw new Error('DbSearcher closed');
@@ -361,40 +301,13 @@ class DbSearcher {
try {
const db = this.db;
let result;
//выборка серии по seriesId
const rows = await db.select({
table: 'series',
where: `@@id(${db.esc(seriesId)})`
});
if (this.config.queryCacheEnabled) {
const key = `series_books-${seriesId}`;
const rows = await db.select({table: 'query_cache', where: `@@id(${db.esc(key)})`});
if (rows.length) {//нашли в кеше
await db.insert({
table: 'query_time',
replace: true,
rows: [{id: key, time: Date.now()}],
});
result = rows[0].value;
} else {//не нашли в кеше
result = await this.selectSeriesBookList(seriesId);
//кладем в кеш
await db.insert({
table: 'query_cache',
replace: true,
rows: [{id: key, value: result}],
});
await db.insert({
table: 'query_time',
replace: true,
rows: [{id: key, time: Date.now()}],
});
}
} else {
result = await this.selectSeriesBookList(seriesId);
}
return result;
return {books: (rows.length ? rows[0].books : '')};
} finally {
this.searchFlag--;
}