Don't run feeds update until after schema update promise
And tweak feed scheduling in general
This commit is contained in:
parent
1372949523
commit
7c020da594
|
@ -27,14 +27,14 @@
|
||||||
|
|
||||||
// Mimics Zotero.Libraries
|
// Mimics Zotero.Libraries
|
||||||
Zotero.Feeds = new function() {
|
Zotero.Feeds = new function() {
|
||||||
var _initTimeoutID;
|
|
||||||
var _initPromise;
|
var _initPromise;
|
||||||
|
var _updating;
|
||||||
|
|
||||||
this.init = function () {
|
this.init = function () {
|
||||||
_initTimeoutID = setTimeout(() => {
|
// Delay initialization for tests
|
||||||
_initTimeoutID = null;
|
_initPromise = Zotero.Schema.schemaUpdatePromise.delay(5000).then(() => {
|
||||||
_initPromise = this.scheduleNextFeedCheck().then(() => _initPromise = null);
|
this.scheduleNextFeedCheck().then(() => _initPromise = null);
|
||||||
}, 5000);
|
});
|
||||||
|
|
||||||
Zotero.SyncedSettings.onSyncDownload.addListener(Zotero.Libraries.userLibraryID, 'feeds',
|
Zotero.SyncedSettings.onSyncDownload.addListener(Zotero.Libraries.userLibraryID, 'feeds',
|
||||||
(oldValue, newValue, conflict) => {
|
(oldValue, newValue, conflict) => {
|
||||||
|
@ -42,22 +42,27 @@ Zotero.Feeds = new function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Zotero.Notifier.registerObserver({notify: function(event) {
|
Zotero.Notifier.registerObserver(
|
||||||
|
{
|
||||||
|
notify: async function (event) {
|
||||||
if (event == 'finish') {
|
if (event == 'finish') {
|
||||||
// Don't update during tests, since the database will have been closed
|
// Don't update during tests, since the database will have been closed
|
||||||
if (Zotero.test) return;
|
if (Zotero.test) return;
|
||||||
|
|
||||||
|
if (_initPromise) {
|
||||||
|
await _initPromise;
|
||||||
|
}
|
||||||
Zotero.Feeds.updateFeeds();
|
Zotero.Feeds.updateFeeds();
|
||||||
}
|
}
|
||||||
}}, ['sync'], 'feedsUpdate');
|
},
|
||||||
|
},
|
||||||
|
['sync'],
|
||||||
|
'feedsUpdate'
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.uninit = function () {
|
this.uninit = function () {
|
||||||
// Cancel feed check if not yet run
|
// Cancel initialization if in progress
|
||||||
if (_initTimeoutID) {
|
|
||||||
clearTimeout(_initTimeoutID);
|
|
||||||
_initTimeoutID = null
|
|
||||||
}
|
|
||||||
// Cancel feed check if in progress
|
|
||||||
if (_initPromise) {
|
if (_initPromise) {
|
||||||
_initPromise.cancel();
|
_initPromise.cancel();
|
||||||
}
|
}
|
||||||
|
@ -246,6 +251,11 @@ Zotero.Feeds = new function() {
|
||||||
|
|
||||||
let globalFeedCheckDelay = Zotero.Promise.resolve();
|
let globalFeedCheckDelay = Zotero.Promise.resolve();
|
||||||
this.scheduleNextFeedCheck = Zotero.Promise.coroutine(function* () {
|
this.scheduleNextFeedCheck = Zotero.Promise.coroutine(function* () {
|
||||||
|
// Don't schedule if already updating, since another check is scheduled at the end
|
||||||
|
if (_updating) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.debug("Scheduling next feed update");
|
Zotero.debug("Scheduling next feed update");
|
||||||
let sql = "SELECT ( CASE "
|
let sql = "SELECT ( CASE "
|
||||||
+ "WHEN lastCheck IS NULL THEN 0 "
|
+ "WHEN lastCheck IS NULL THEN 0 "
|
||||||
|
@ -266,6 +276,7 @@ Zotero.Feeds = new function() {
|
||||||
this._nextFeedCheck = Zotero.Promise.delay(nextCheck);
|
this._nextFeedCheck = Zotero.Promise.delay(nextCheck);
|
||||||
Zotero.Promise.all([this._nextFeedCheck, globalFeedCheckDelay])
|
Zotero.Promise.all([this._nextFeedCheck, globalFeedCheckDelay])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this._nextFeedCheck = null;
|
||||||
globalFeedCheckDelay = Zotero.Promise.delay(60000); // Don't perform auto-updates more than once per minute
|
globalFeedCheckDelay = Zotero.Promise.delay(60000); // Don't perform auto-updates more than once per minute
|
||||||
return this.updateFeeds()
|
return this.updateFeeds()
|
||||||
})
|
})
|
||||||
|
@ -282,6 +293,16 @@ Zotero.Feeds = new function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.updateFeeds = Zotero.Promise.coroutine(function* () {
|
this.updateFeeds = Zotero.Promise.coroutine(function* () {
|
||||||
|
if (_updating) {
|
||||||
|
Zotero.debug("Feed update already in progress");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this._nextFeedCheck) {
|
||||||
|
this._nextFeedCheck.cancel();
|
||||||
|
this._nextFeedCheck = null;
|
||||||
|
}
|
||||||
|
_updating = true;
|
||||||
|
try {
|
||||||
let sql = "SELECT libraryID AS id FROM feeds "
|
let sql = "SELECT libraryID AS id FROM feeds "
|
||||||
+ "WHERE refreshInterval IS NOT NULL "
|
+ "WHERE refreshInterval IS NOT NULL "
|
||||||
+ "AND ( lastCheck IS NULL "
|
+ "AND ( lastCheck IS NULL "
|
||||||
|
@ -293,7 +314,10 @@ Zotero.Feeds = new function() {
|
||||||
yield feed.waitForDataLoad('item');
|
yield feed.waitForDataLoad('item');
|
||||||
yield feed._updateFeed();
|
yield feed._updateFeed();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
_updating = false;
|
||||||
|
}
|
||||||
Zotero.debug("All feed updates done");
|
Zotero.debug("All feed updates done");
|
||||||
this.scheduleNextFeedCheck();
|
this.scheduleNextFeedCheck();
|
||||||
});
|
});
|
||||||
|
|
|
@ -306,11 +306,11 @@ describe("Zotero.Feed", function() {
|
||||||
var modifiedFeedUrl = getTestDataUrl("feedModified.rss");
|
var modifiedFeedUrl = getTestDataUrl("feedModified.rss");
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
scheduleNextFeedCheck = sinon.stub(Zotero.Feeds, 'scheduleNextFeedCheck');
|
scheduleNextFeedCheck = sinon.stub(Zotero.Feeds, 'scheduleNextFeedCheck').resolves();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function* (){
|
beforeEach(function* (){
|
||||||
scheduleNextFeedCheck.reset();
|
scheduleNextFeedCheck.resetHistory();
|
||||||
feed = yield createFeed();
|
feed = yield createFeed();
|
||||||
feed._feedUrl = feedUrl;
|
feed._feedUrl = feedUrl;
|
||||||
yield feed.updateFeed();
|
yield feed.updateFeed();
|
||||||
|
@ -325,12 +325,10 @@ describe("Zotero.Feed", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should schedule next feed check', function* () {
|
it('should schedule next feed check', function* () {
|
||||||
|
|
||||||
let feed = yield createFeed();
|
let feed = yield createFeed();
|
||||||
feed._feedUrl = feedUrl;
|
feed._feedUrl = feedUrl;
|
||||||
yield feed.updateFeed();
|
yield feed.updateFeed();
|
||||||
assert.equal(scheduleNextFeedCheck.called, true);
|
assert.equal(scheduleNextFeedCheck.called, true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add new feed items', function* () {
|
it('should add new feed items', function* () {
|
||||||
|
|
|
@ -166,7 +166,7 @@ describe("Zotero.Feeds", function () {
|
||||||
before(function* () {
|
before(function* () {
|
||||||
yield clearFeeds();
|
yield clearFeeds();
|
||||||
|
|
||||||
sinon.stub(Zotero.Feeds, 'scheduleNextFeedCheck');
|
sinon.stub(Zotero.Feeds, 'scheduleNextFeedCheck').resolves();
|
||||||
_updateFeed = sinon.stub(Zotero.Feed.prototype, '_updateFeed').resolves();
|
_updateFeed = sinon.stub(Zotero.Feed.prototype, '_updateFeed').resolves();
|
||||||
let url = getTestDataUrl("feed.rss");
|
let url = getTestDataUrl("feed.rss");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user