Browse Source

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

Book Pauk 2 years ago
parent
commit
09b7c38348
1 changed files with 17 additions and 104 deletions
  1. 17 104
      server/core/DbSearcher.js

+ 17 - 104
server/core/DbSearcher.js

@@ -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;
-
-            if (this.config.queryCacheEnabled) {
-                const key = `author_books-${authorId}`;
-                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()}],
-                    });
+            //выборка автора по authorId
+            const rows = await db.select({
+                table: 'author_book',
+                where: `@@id(${db.esc(authorId)})`
+            });
 
-                    result = rows[0].value;
-                } else {//не нашли в кеше
-                    result = await this.selectBookList(authorId);
+            let author = '';
+            let books = '';
 
-                    //кладем в кеш
-                    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;
-
-            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);
-            }
+            //выборка серии по seriesId
+            const rows = await db.select({
+                table: 'series',
+                where: `@@id(${db.esc(seriesId)})`
+            });
 
-            return result;
+            return {books: (rows.length ? rows[0].books : '')};
         } finally {
             this.searchFlag--;
         }