From b441893d02e5c95a371dabe11c12a6246124b50c Mon Sep 17 00:00:00 2001 From: Alexandre Rossi Date: Mon, 23 Sep 2019 15:19:42 +0200 Subject: [PATCH] offline: batch upload offline status changes This is to avoid getting: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. after reading a lot of items offline. --- assets/js/selfoss-db.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/assets/js/selfoss-db.js b/assets/js/selfoss-db.js index a11c52565f..36bbc24469 100644 --- a/assets/js/selfoss-db.js +++ b/assets/js/selfoss-db.js @@ -19,6 +19,8 @@ selfoss.dbOnline = { statsDirty: false, firstSync: true, + itemsDownloadBatchSize: 15, + statusUploadBatchSize: 200, _syncBegin: function() { if (!selfoss.dbOnline.syncing) { @@ -110,7 +112,7 @@ selfoss.dbOnline = { if (selfoss.db.storage) { syncParams.itemsSinceId = selfoss.dbOffline.lastItemId; syncParams.itemsNotBefore = selfoss.dbOffline.newestGCedEntry.toISOString(); - syncParams.itemsHowMany = selfoss.filter.itemsPerPage; + syncParams.itemsHowMany = selfoss.dbOnline.itemsDownloadBatchSize; } selfoss.dbOnline.statsDirty = false; @@ -146,21 +148,24 @@ selfoss.dbOnline = { selfoss.dbOffline .shouldLoadEntriesOnline = 'lastId' in data && data.lastId - selfoss.dbOffline.lastItemId > - 2 * selfoss.filter.itemsPerPage; + 2 * selfoss.dbOnline.itemsDownloadBatchSize; selfoss.dbOffline.storeEntries(data.newItems) .then(function() { selfoss.dbOffline.storeLastUpdate(dataDate); - selfoss.dbOnline._syncDone(); - - // fetch more if server has more - if (selfoss.dbOffline.newerEntriesMissing) { - selfoss.dbOnline.sync(); - } }); } + if (selfoss.dbOffline.newerEntriesMissing + || selfoss.dbOffline.needsSync) { + // There are still new items to fetch + // or statuses to send + syncing.then(function() { + selfoss.dbOffline.sendNewStatuses(); + }); + } + if ('itemUpdates' in data) { // refresh entry statuses in db and dequeue queued // statuses but do not calculate stats as they are taken @@ -703,8 +708,9 @@ selfoss.dbOffline = { sendNewStatuses: function() { - selfoss.db.storage.statusq.toArray().then(statuses => { - return statuses.map(s => { + selfoss.dbOffline._tr('r', selfoss.db.storage.statusq, async() => { + const offlineStatusesCount = await selfoss.db.storage.statusq.count(); + const statuses = (await selfoss.db.storage.statusq.limit(selfoss.dbOnline.statusUploadBatchSize).toArray()).map(s => { let statusUpdate = { id: s.entryId, datetime: s.datetime @@ -713,10 +719,12 @@ selfoss.dbOffline = { return statusUpdate; }); - }).then(statuses => { + const s = statuses.length > 0 ? statuses : undefined; - selfoss.dbOnline.sync(s, true).then(function() { - selfoss.dbOffline.needsSync = false; + selfoss.dbOnline.sync(s, true).then(() => { + if (offlineStatusesCount <= selfoss.dbOnline.statusUploadBatchSize) { + selfoss.dbOffline.needsSync = false; + } }); });