Рефакторинг
This commit is contained in:
@@ -55,7 +55,7 @@ class DbSearcher {
|
|||||||
async selectAuthorIds(query) {
|
async selectAuthorIds(query) {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
let authorIds = new Set();
|
let authorIds = [];
|
||||||
|
|
||||||
//сначала выберем все id авторов по фильтру
|
//сначала выберем все id авторов по фильтру
|
||||||
//порядок id соответсвует ASC-сортировке по author
|
//порядок id соответсвует ASC-сортировке по author
|
||||||
@@ -69,7 +69,7 @@ class DbSearcher {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const row of authorRows)
|
for (const row of authorRows)
|
||||||
authorIds.add(row.id);
|
authorIds.push(row.id);
|
||||||
} else {//все авторы
|
} else {//все авторы
|
||||||
if (!db.searchCache.authorIdsAll) {
|
if (!db.searchCache.authorIdsAll) {
|
||||||
const authorRows = await db.select({
|
const authorRows = await db.select({
|
||||||
@@ -77,18 +77,17 @@ class DbSearcher {
|
|||||||
dirtyIdsOnly: true,
|
dirtyIdsOnly: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
db.searchCache.authorIdsAll = [];
|
|
||||||
for (const row of authorRows) {
|
for (const row of authorRows) {
|
||||||
authorIds.add(row.id);
|
authorIds.push(row.id);
|
||||||
db.searchCache.authorIdsAll.push(row.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.searchCache.authorIdsAll = authorIds;
|
||||||
} else {//оптимизация
|
} else {//оптимизация
|
||||||
authorIds = new Set(db.searchCache.authorIdsAll);
|
authorIds = db.searchCache.authorIdsAll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const idsArr = [];
|
const idsArr = [];
|
||||||
idsArr.push(authorIds);
|
|
||||||
|
|
||||||
//серии
|
//серии
|
||||||
if (query.series && query.series !== '*') {
|
if (query.series && query.series !== '*') {
|
||||||
@@ -176,12 +175,13 @@ class DbSearcher {
|
|||||||
idsArr.push(ids);
|
idsArr.push(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idsArr.length > 1)
|
if (idsArr.length) {
|
||||||
authorIds = utils.intersectSet(idsArr);
|
//ищем пересечение множеств
|
||||||
|
idsArr.push(new Set(authorIds));
|
||||||
|
authorIds = Array.from(utils.intersectSet(idsArr));
|
||||||
|
}
|
||||||
|
|
||||||
//сортировка
|
//сортировка
|
||||||
authorIds = Array.from(authorIds);
|
|
||||||
|
|
||||||
authorIds.sort((a, b) => a - b);
|
authorIds.sort((a, b) => a - b);
|
||||||
|
|
||||||
return authorIds;
|
return authorIds;
|
||||||
|
|||||||
Reference in New Issue
Block a user