1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Make indexeddb startup faster

Don't needlessly transfer data from the worker to the main script
only to immediately transfer it right back again.
This commit is contained in:
David Baker
2017-04-06 18:09:12 +01:00
parent 18806e5524
commit 039a3e258b
4 changed files with 39 additions and 47 deletions

View File

@@ -136,6 +136,24 @@ LocalIndexedDBStoreBackend.prototype = {
});
},
/**
* Having connected, load initial data from the database and prepare for use
*/
init: function() {
return q.all([
this._loadAccountData(),
this._loadSyncData(),
]).then(([accountData, syncData]) => {
this._syncAccumulator.accumulate({
next_batch: syncData.nextBatch,
rooms: syncData.roomsData,
account_data: {
events: accountData,
},
});
});
},
/**
* Clear the entire database. This should be used when logging out of a client
* to prevent mixing data between accounts.
@@ -250,7 +268,7 @@ LocalIndexedDBStoreBackend.prototype = {
* sync.
* @return {Promise<Object[]>} A list of presence events in their raw form.
*/
loadUserPresenceEvents: function() {
getUserPresenceEvents: function() {
return q.try(() => {
const txn = this.db.transaction(["users"], "readonly");
const store = txn.objectStore("users");
@@ -264,7 +282,7 @@ LocalIndexedDBStoreBackend.prototype = {
* Load all the account data events from the database. This is not cached.
* @return {Promise<Object[]>} A list of raw global account events.
*/
loadAccountData: function() {
_loadAccountData: function() {
return q.try(() => {
const txn = this.db.transaction(["accountData"], "readonly");
const store = txn.objectStore("accountData");
@@ -278,7 +296,7 @@ LocalIndexedDBStoreBackend.prototype = {
* Load the sync data from the database.
* @return {Promise<Object>} An object with "roomsData" and "nextBatch" keys.
*/
loadSyncData: function() {
_loadSyncData: function() {
return q.try(() => {
const txn = this.db.transaction(["sync"], "readonly");
const store = txn.objectStore("sync");