diff --git a/src/store/indexeddb.js b/src/store/indexeddb.js index 8fa102eac..30faf40ce 100644 --- a/src/store/indexeddb.js +++ b/src/store/indexeddb.js @@ -284,19 +284,15 @@ IndexedDBStore.prototype.getSyncAccumulator = function() { }; /** - * Set a new sync token and possibly write to the database. - * Overrides MatrixInMemoryStore. - * @param {string} token The new sync token - * @return {?Promise} A promise if this sync token triggered a write to the - * database, else null. Promise resolves after the write completes. + * Possibly write data to the database. + * @return {Promise} Promise resolves after the write completes. */ -IndexedDBStore.prototype.setSyncToken = function(token) { - MatrixInMemoryStore.prototype.setSyncToken.call(this, token); +IndexedDBStore.prototype.save = function() { const now = Date.now(); if (now - this._syncTs > WRITE_DELAY_MS) { return this._syncToDatabase().catch((err) => {console.error("sync fail:", err);}); } - return null; + return q(); }; IndexedDBStore.prototype._setSyncData = function(nextBatch, roomsData) { diff --git a/src/store/memory.js b/src/store/memory.js index cf52f8074..b14b25f7d 100644 --- a/src/store/memory.js +++ b/src/store/memory.js @@ -274,4 +274,9 @@ module.exports.MatrixInMemoryStore.prototype = { getAccountData: function(eventType) { return this.accountData[eventType]; }, + + /** + * Save does nothing as there is no backing data store. + */ + save: function() {}, }; diff --git a/src/store/stub.js b/src/store/stub.js index ad5e3580c..ed9da2ef3 100644 --- a/src/store/stub.js +++ b/src/store/stub.js @@ -179,6 +179,11 @@ StubStore.prototype = { getAccountData: function(eventType) { }, + + /** + * Save does nothing as there is no backing data store. + */ + save: function() {}, }; /** Stub Store class. */ diff --git a/src/sync.js b/src/sync.js index 8931ec92e..c8d0ace77 100644 --- a/src/sync.js +++ b/src/sync.js @@ -570,6 +570,10 @@ SyncApi.prototype._sync = function(syncOptions) { // keep emitting SYNCING -> SYNCING for clients who want to do bulk updates self._updateSyncState("SYNCING", syncEventData); + // tell databases that everything is now in a consistent state and can be + // saved. + client.store.save(); + self._sync(syncOptions); }, function(err) { if (!self._running) {