1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-07 05:22:15 +03:00

clear sync data on toggling LL,also throw spec. error and delegate clear

the sync data needs to be cleared toggling in both directions:
 not LL -> LL: you want to get rid of all the excess state in the
               sync data to get the RAM benefits
 LL -> not LL: you want to fill the sync data state again
               because getOutOfBandMembers won't be called
This commit is contained in:
Bruno Windels
2018-09-26 12:39:56 +01:00
parent 58e3c72446
commit 54bff81470
3 changed files with 38 additions and 13 deletions

View File

@@ -44,6 +44,7 @@ const ContentHelpers = require("./content-helpers");
import ReEmitter from './ReEmitter';
import RoomList from './crypto/RoomList';
import {InvalidStoreError} from './errors';
const LAZY_LOADING_MESSAGES_FILTER = {
@@ -3116,12 +3117,10 @@ MatrixClient.prototype.startClient = async function(opts) {
}
}
// need to vape the store when enabling LL and wasn't enabled before
if (opts.lazyLoadMembers) {
const shouldClear = await this._shouldClearSyncDataIfLL();
if (shouldClear) {
await this.store.deleteAllData();
throw new Error("vaped the store, you need to resync");
}
const shouldClear = await this._shouldClearSyncDataIfLLToggled(opts.lazyLoadMembers);
if (shouldClear) {
const reason = InvalidStoreError.TOGGLED_LAZY_LOADING;
throw new InvalidStoreError(reason);
}
if (opts.lazyLoadMembers && this._crypto) {
this._crypto.enableLazyLoading();
@@ -3140,18 +3139,19 @@ MatrixClient.prototype.startClient = async function(opts) {
this._syncApi.sync();
};
/** @return {bool} need to clear the store when enabling LL and wasn't enabled before? */
MatrixClient.prototype._shouldClearSyncDataIfLL = async function() {
let hadLLEnabledBefore = false;
/** @return {bool} need to clear the store when toggling LL compared to previous session? */
MatrixClient.prototype._shouldClearSyncDataIfLLToggled = async function(lazyLoadMembers) {
lazyLoadMembers = !!lazyLoadMembers;
// assume it was turned off before
// if we don't know any better
let lazyLoadMembersBefore = false;
const isStoreNewlyCreated = await this.store.isNewlyCreated();
if (!isStoreNewlyCreated) {
const prevClientOptions = await this.store.getClientOptions();
if (prevClientOptions) {
hadLLEnabledBefore = !!prevClientOptions.lazyLoadMembers;
}
if (!hadLLEnabledBefore) {
return true;
lazyLoadMembersBefore = !!prevClientOptions.lazyLoadMembers;
}
return lazyLoadMembersBefore !== lazyLoadMembers;
}
return false;
};