Рефакторинг, небольшие улучшения

This commit is contained in:
Book Pauk
2022-11-28 16:11:54 +07:00
parent a6aa8d8e95
commit af575a87a2
5 changed files with 19 additions and 13 deletions

View File

@@ -253,7 +253,7 @@ export default class BaseList {
result = await this.api.getAuthorBookList(authorId);
}
return (result.books ? JSON.parse(result.books) : []);
return result.books;
} catch (e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
}
@@ -276,7 +276,7 @@ export default class BaseList {
result = await this.api.getSeriesBookList(series);
}
return (result.books ? JSON.parse(result.books) : []);
return result.books;
} catch (e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
}

View File

@@ -8,6 +8,8 @@ const abStore = localForage.createInstance({
name: 'authorBooksStorage'
});
const storageVersion = '1';
class AuthorBooksStorage {
constructor() {
}
@@ -17,6 +19,8 @@ class AuthorBooksStorage {
}
async setData(key, data) {
key += storageVersion;
if (typeof data !== 'string')
throw new Error('AuthorBooksStorage: data must be a string');
@@ -25,6 +29,8 @@ class AuthorBooksStorage {
}
async getData(key) {
key += storageVersion;
const item = await abStore.getItem(key);
//обновим addTime
@@ -34,9 +40,9 @@ class AuthorBooksStorage {
return item;
}
async removeData(key) {
await abStore.removeItem(key);
await abStore.removeItem(`addTime-${key}`);
async _removeData(fullKey) {
await abStore.removeItem(fullKey);
await abStore.removeItem(`addTime-${fullKey}`);
}
async cleanStorage() {
@@ -62,7 +68,7 @@ class AuthorBooksStorage {
}
if (size > maxDataSize && toDel) {
await this.removeData(toDel);
await this._removeData(toDel);
} else {
break;
}

View File

@@ -625,14 +625,14 @@ class DbSearcher {
const rows = await this.restoreBooks('author', [authorId]);
let authorName = '';
let books = '';
let books = [];
if (rows.length) {
authorName = rows[0].name;
books = rows[0].books;
}
return {author: authorName, books: (books && books.length ? JSON.stringify(books) : '')};
return {author: authorName, books};
} finally {
this.searchFlag--;
}
@@ -659,7 +659,7 @@ class DbSearcher {
where: `return Array.from(@dirtyIndexLR('value', ${db.esc(series)}, ${db.esc(series)}))`
});
let books;
let books = [];
if (rows.length && rows[0].rawResult.length) {
//выборка книг серии
const bookRows = await this.restoreBooks('series', [rows[0].rawResult[0]])
@@ -668,7 +668,7 @@ class DbSearcher {
books = bookRows[0].books;
}
return {books: (books && books.length ? JSON.stringify(books) : '')};
return {books};
} finally {
this.searchFlag--;
}

View File

@@ -79,7 +79,7 @@ class AuthorPage extends BasePage {
const bookList = await this.webWorker.getSeriesBookList(query.series);
if (bookList.books) {
let books = JSON.parse(bookList.books);
let books = bookList.books;
const booksAll = this.filterBooks(books, {del: 0});
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
const sorted = this.sortSeriesBooks(filtered);
@@ -122,7 +122,7 @@ class AuthorPage extends BasePage {
const bookList = await this.webWorker.getAuthorBookList(0, query.author.substring(1));
if (bookList.books) {
let books = JSON.parse(bookList.books);
let books = bookList.books;
books = this.sortBooks(this.filterBooks(books, query));
for (const b of books) {

View File

@@ -44,7 +44,7 @@ class SeriesPage extends BasePage {
const bookList = await this.webWorker.getSeriesBookList(query.series.substring(1));
if (bookList.books) {
let books = JSON.parse(bookList.books);
let books = bookList.books;
const booksAll = this.filterBooks(books, {del: 0});
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
const sorted = this.sortSeriesBooks(filtered);