diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index 69e43a4d..9cc55eba 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -476,7 +476,10 @@ class Reader { this.dualPageMode = settings.dualPageMode; this.userWallpapers = settings.userWallpapers; this.bucEnabled = settings.bucEnabled; + this.bucSizeDiff = settings.bucSizeDiff; this.bucSetOnNew = settings.bucSetOnNew; + this.bucCancelEnabled = settings.bucCancelEnabled; + this.bucCancelDays = settings.bucCancelDays; this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys); this.$root.readerActionByKeyEvent = (event) => { @@ -604,13 +607,50 @@ class Reader { await utils.sleep(1000);//чтобы не ддосить сервер } + const checkSetTime = {}; //проставим новые размеры у книг for (const book of sorted) { + if (book.deleted) + continue; + //размер 0 считаем отсутствующим if (book.url && bucSize[book.url] && bucSize[book.url] !== book.bucSize) { book.bucSize = bucSize[book.url]; await bookManager.recentSetItem(book); } + + //подготовка к следующему шагу, ищем книгу по url с максимальной датой установки checkBucTime/loadTime + //от этой даты будем потом отсчитывать bucCancelDays + if (updateUrls.has(book.url)) { + let rec = checkSetTime[book.url] || {time: 0, loadTime: 0}; + + const time = (book.checkBucTime ? book.checkBucTime : (rec.loadTime || 0)); + if (time > rec.time || (time == rec.time && (book.loadTime > rec.loadTime))) + rec = {time, loadTime: book.loadTime, key: book.key}; + + checkSetTime[book.url] = rec; + } + } + + //bucCancelEnabled и bucCancelDays + //снимем флаг checkBuc у необновлявшихся bucCancelDays + if (this.bucCancelEnabled) { + for (const rec of Object.values(checkSetTime)) { + if (rec.time && Date.now() - rec.time > this.bucCancelDays*24*3600*1000) { + const book = await bookManager.getRecentBook({key: rec.key}); + const needBookUpdate = + book.checkBuc + && book.bucSize + && utils.hasProp(book, 'downloadSize') + && book.bucSize !== book.downloadSize + && (book.bucSize - book.downloadSize >= this.bucSizeDiff) + ; + + if (book && !needBookUpdate) { + await bookManager.setCheckBuc(book, undefined);//!!! + } + } + } } await this.$refs.recentBooksPage.updateTableData(); @@ -1251,6 +1291,7 @@ class Reader { this.checkBookPosPercent(); this.activateClickMapPage();//no await + this.$refs.recentBooksPage.updateTableData();//no await return; } diff --git a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue index e23e3ff9..32a07476 100644 --- a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue +++ b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue @@ -147,8 +147,8 @@ {{ item.desc.title }}
- Размер: {{ item.downloadSize }} → {{ item.bucSize }}, - {{ item.bucSize - item.downloadSize > 0 ? '+' : '' }}{{ item.bucSize - item.downloadSize }} + Размер: {{ item.bucSize - item.downloadSize > 0 ? '+' : '' }}{{ item.bucSize - item.downloadSize }} + ({{ item.downloadSize }} → {{ item.bucSize }})
@@ -231,7 +231,12 @@ @update:model-value="checkBucChange(item)" > - Проверять обновления +
+ Проверка обновлений отключена автоматически
т.к. книга не обновлялась {{ bucCancelDays }} дней +
+
+ {{ (item.checkBuc ? 'Проверка обновлений книги включена' : 'Проверка обновлений книги отключена') }} +
@@ -289,6 +294,7 @@ class RecentBooksPage { bucEnabled = false; bucSizeDiff = 0; bucSetOnNew = false; + bucCancelDays = 0; needBookUpdateCount = 0; showArchive = false; @@ -332,6 +338,7 @@ class RecentBooksPage { this.bucEnabled = settings.bucEnabled; this.bucSizeDiff = settings.bucSizeDiff; this.bucSetOnNew = settings.bucSetOnNew; + this.bucCancelDays = settings.bucCancelDays; } get settings() { @@ -403,8 +410,8 @@ class RecentBooksPage { inGroup: false, coverPageUrl: book.coverPageUrl, - showCheckBuc: !this.showArchive && utils.hasProp(book, 'downloadSize'), - checkBuc: !!book.checkBuc, + showCheckBuc: !this.showArchive && utils.hasProp(book, 'downloadSize') && book.url.indexOf('disk://') !== 0, + checkBuc: book.checkBuc, needBookUpdate: ( !this.showArchive && book.checkBuc diff --git a/client/components/Reader/SettingsPage/UpdateTab.inc b/client/components/Reader/SettingsPage/UpdateTab.inc index fe5d0cbe..f5e193e4 100644 --- a/client/components/Reader/SettingsPage/UpdateTab.inc +++ b/client/components/Reader/SettingsPage/UpdateTab.inc @@ -27,17 +27,7 @@
- - Автопроверка для вновь загружаемых - - Автоматически устанавливать флаг проверки
- обновлений для всех вновь загружаемых книг -
-
-
- -
-
Разница размеров
+
Разница размеров
@@ -48,3 +38,39 @@
+ +
+
+ + Автопроверка для вновь загружаемых + + Автоматически устанавливать флаг проверки
+ обновлений для всех вновь загружаемых книг +
+
+
+ +
+
+ + Отменять проверку через {{ bucCancelDays }} дней{{ (bucCancelEnabled ? ':' : '') }} + + Снимать флаг проверки с книги, если не было
+ обновлений в течение {{ bucCancelDays }} дней +
+
+
+ +
+
+
+
+ + + + Снимать флаг проверки с книги, если не было
+ обновлений в течение {{ bucCancelDays }} дней +
+
+
+ diff --git a/client/components/Reader/share/bookManager.js b/client/components/Reader/share/bookManager.js index 651dda1a..8308cf0d 100644 --- a/client/components/Reader/share/bookManager.js +++ b/client/components/Reader/share/bookManager.js @@ -487,7 +487,7 @@ class BookManager { await this.recentSetItem(item); } - async setCheckBuc(value, checkBuc = true) { + async setCheckBuc(value, checkBuc) { const item = this.recent[value.key]; const updateItems = []; @@ -495,7 +495,7 @@ class BookManager { if (item.sameBookKey !== undefined) { const sorted = this.getSortedRecent(); for (const book of sorted) { - if (book.sameBookKey === item.sameBookKey) + if (!book.deleted && book.sameBookKey === item.sameBookKey) updateItems.push(book); } } else { @@ -503,8 +503,11 @@ class BookManager { } } + const now = Date.now(); for (const book of updateItems) { book.checkBuc = checkBuc; + if (checkBuc) + book.checkBucTime = now; await this.recentSetItem(book); } } diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index 7af61591..3c72299a 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -185,7 +185,7 @@ const settingDefaults = { fontShifts: {}, showToolButton: {}, - toolBarHideOnScroll: true, + toolBarHideOnScroll: false, userHotKeys: {}, userWallpapers: [], @@ -196,6 +196,8 @@ const settingDefaults = { bucEnabled: true, // общее включение/выключение проверки обновлений bucSizeDiff: 1, // разница в размерах файла, при которой показывать наличие обновления bucSetOnNew: true, // автоматически включать проверку обновлений для вновь загружаемых файлов + bucCancelEnabled: true, // вкл/выкл отмену проверки книг через bucCancelDays + bucCancelDays: 90, // количество дней, через которое отменяется проверка книги, при условии отсутствия обновлений за это время //для SettingsPage needUpdateSettingsView: 0, diff --git a/server/core/BookUpdateChecker/BUCClient.js b/server/core/BookUpdateChecker/BUCClient.js index 4a49508d..7ea33e83 100644 --- a/server/core/BookUpdateChecker/BUCClient.js +++ b/server/core/BookUpdateChecker/BUCClient.js @@ -249,7 +249,7 @@ class BUCClient { this.periodicSendBookUrls();//no await this.periodicSync();//no await - log(`BUC Client started`); + log(`BUC Client Worker started`); } catch (e) { log(LM_FATAL, e.stack); ayncExit.exit(1); diff --git a/server/core/BookUpdateChecker/BUCServer.js b/server/core/BookUpdateChecker/BUCServer.js index f2822962..3c873b97 100644 --- a/server/core/BookUpdateChecker/BUCServer.js +++ b/server/core/BookUpdateChecker/BUCServer.js @@ -26,8 +26,8 @@ class BUCServer { this.periodicCheckWait = 500;//пауза, если нечего делать this.cleanQueryInterval = 300*dayMs;//интервал очистки устаревших - this.oldQueryInterval = 30*dayMs;//интервал устаревания запроса на обновление - this.checkingInterval = 3*hourMs;//интервал проверки обновления одного и того же файла + this.oldQueryInterval = 14*dayMs;//интервал устаревания запроса на обновление + this.checkingInterval = 5*hourMs;//интервал проверки обновления одного и того же файла this.sameHostCheckInterval = 1000;//интервал проверки файла на том же сайте, не менее } else { this.maxCheckQueueLength = 10;//максимальная длина checkQueue @@ -134,6 +134,7 @@ class BUCServer { id, queryTime: now, checkTime: 0, // 0 - never checked + etag: '', modTime: '', size: 0, checkSum: '', //sha256 @@ -184,7 +185,7 @@ class BUCServer { } rows = await db.select({table: 'buc', count: true}); - log(LM_WARN, `'buc' table length: ${rows[0].count}`); + log(LM_WARN, `'buc' table size: ${rows[0].count}`); now = Date.now(); //выборка кандидатов @@ -199,24 +200,30 @@ class BUCServer { ` }); -//console.log(rows); - + //формирование checkQueue if (rows.length) { const ids = []; + const rowsToPush = []; + //сначала выберем сколько надо for (const row of rows) { - if (this.checkQueue.length >= this.maxCheckQueueLength) + if (this.checkQueue.length + rowsToPush.length >= this.maxCheckQueueLength) break; + rowsToPush.push(row); ids.push(row.id); - this.checkQueue.push(row); } + //установим у них флаг "в обработке" await db.update({ table: 'buc', mod: `(r) => r.state = 1`, where: `@@id(${db.esc(ids)})` }); + + //пушим в очередь, после этого их обработает periodicCheck + for (const row of rowsToPush) + this.checkQueue.push(row); log(LM_WARN, `checkQueue: added ${ids.length} recs, total ${this.checkQueue.length}`); } @@ -249,13 +256,21 @@ class BUCServer { try { let unchanged = true; - let size = 0; let hash = ''; const headers = await this.down.head(row.id); - const modTime = headers['last-modified'] - if (!modTime || !row.modTime || (modTime !== row.modTime)) { + const etag = headers['etag'] || ''; + const modTime = headers['last-modified'] || ''; + let size = parseInt(headers['content-length'], 10) || 0; + + //log(row.id); + //log(`etag: ${etag}, modTime: ${modTime}, size: ${size}`) + + if ((!etag || !row.etag || (etag !== row.etag)) + && (!modTime || !row.modTime || (modTime !== row.modTime)) + && (!size || !row.size || (size !== row.size)) + ) { const downdata = await this.down.load(row.id); size = downdata.length; @@ -267,6 +282,7 @@ class BUCServer { table: 'buc', mod: `(r) => { r.checkTime = ${db.esc(Date.now())}; + r.etag = ${(unchanged ? 'r.etag' : db.esc(etag))}; r.modTime = ${(unchanged ? 'r.modTime' : db.esc(modTime))}; r.size = ${(unchanged ? 'r.size' : db.esc(size))}; r.checkSum = ${(unchanged ? 'r.checkSum' : db.esc(hash))}; @@ -291,6 +307,8 @@ class BUCServer { }`, where: `@@id(${db.esc(row.id)})` }); + + log(LM_ERR, `error ${row.id} > ${e.stack ? e.stack : e.message}`); } finally { (async() => { await utils.sleep(this.sameHostCheckInterval); @@ -319,9 +337,9 @@ class BUCServer { for (let i = 0; i < 10; i++) this.periodicCheck();//no await - log(`------------------`); - log(`BUC Server started`); - log(`------------------`); + log(`-------------------------`); + log(`BUC Server Worker started`); + log(`-------------------------`); } catch (e) { log(LM_FATAL, e.stack); ayncExit.exit(1);