You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
delay saving so we can batch multiple operations
This commit is contained in:
@@ -87,6 +87,9 @@ export default class DeviceList {
|
|||||||
|
|
||||||
// Set whenever changes are made other than setting the sync token
|
// Set whenever changes are made other than setting the sync token
|
||||||
this._dirty = false;
|
this._dirty = false;
|
||||||
|
|
||||||
|
// Timeout for a scheduled save
|
||||||
|
this._saveTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,23 +116,26 @@ export default class DeviceList {
|
|||||||
/**
|
/**
|
||||||
* Save the device tracking state to storage, if any changes are
|
* Save the device tracking state to storage, if any changes are
|
||||||
* pending other than updating the sync token
|
* pending other than updating the sync token
|
||||||
* Before calling this, the caller must ensure that the state it
|
|
||||||
* has set this object to is consistent, ie. the appropriate sync
|
|
||||||
* token has been set with setSyncToken for any device updates that
|
|
||||||
* have occurred.
|
|
||||||
*/
|
*/
|
||||||
async saveIfDirty() {
|
async saveIfDirty() {
|
||||||
if (!this._dirty) return;
|
if (!this._dirty) return;
|
||||||
await this._cryptoStore.doTxn(
|
|
||||||
'readwrite', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
|
if (this._saveTimer === null) {
|
||||||
this._cryptoStore.storeEndToEndDeviceData({
|
this._saveTimer = setTimeout(() => {
|
||||||
devices: this._devices,
|
this._saveTimer = null;
|
||||||
trackingStatus: this._deviceTrackingStatus,
|
this._cryptoStore.doTxn(
|
||||||
syncToken: this._syncToken,
|
'readwrite', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
|
||||||
}, txn);
|
this._cryptoStore.storeEndToEndDeviceData({
|
||||||
},
|
devices: this._devices,
|
||||||
);
|
trackingStatus: this._deviceTrackingStatus,
|
||||||
this._dirty = false;
|
syncToken: this._syncToken,
|
||||||
|
}, txn);
|
||||||
|
},
|
||||||
|
).then(() => {
|
||||||
|
this._dirty = false;
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,6 +149,10 @@ export default class DeviceList {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current sync token
|
* Sets the current sync token
|
||||||
|
* The sync token must always be set after any changes made as a result of
|
||||||
|
* data in that sync since setting the sync token to a newer one will mean
|
||||||
|
* those changed will not be synced from the server if a new client starts
|
||||||
|
* up with that data.
|
||||||
*
|
*
|
||||||
* @param {string} st The sync token
|
* @param {string} st The sync token
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user