Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offline: various fixes #1136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions assets/js/selfoss-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ selfoss.dbOnline = {
statsDirty: false,
firstSync: true,

itemsDownloadBatchSize: 15,
statusUploadBatchSize: 200,

_syncBegin: function() {
if (!selfoss.dbOnline.syncing) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
});
});

Expand Down