You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-14 19:22:15 +03:00
Remove the logic that throws when the lazy loading options has changed. (#4124)
* remove InvalidStoreState and the logic that checks for the change in the lazyLoading client option * lint
This commit is contained in:
@@ -14,25 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export enum InvalidStoreState {
|
|
||||||
ToggledLazyLoading,
|
|
||||||
}
|
|
||||||
|
|
||||||
export class InvalidStoreError extends Error {
|
|
||||||
public static TOGGLED_LAZY_LOADING = InvalidStoreState.ToggledLazyLoading;
|
|
||||||
|
|
||||||
public constructor(
|
|
||||||
public readonly reason: InvalidStoreState,
|
|
||||||
public readonly value: any,
|
|
||||||
) {
|
|
||||||
const message =
|
|
||||||
`Store is invalid because ${reason}, ` +
|
|
||||||
`please stop the client, delete all data and start the client again`;
|
|
||||||
super(message);
|
|
||||||
this.name = "InvalidStoreError";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum InvalidCryptoStoreState {
|
export enum InvalidCryptoStoreState {
|
||||||
TooNew = "TOO_NEW",
|
TooNew = "TOO_NEW",
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/sync.ts
51
src/sync.ts
@@ -32,7 +32,6 @@ import { deepCopy, defer, IDeferred, noUnsafeEventProps, promiseMapSeries, unsaf
|
|||||||
import { Filter } from "./filter";
|
import { Filter } from "./filter";
|
||||||
import { EventTimeline } from "./models/event-timeline";
|
import { EventTimeline } from "./models/event-timeline";
|
||||||
import { logger } from "./logger";
|
import { logger } from "./logger";
|
||||||
import { InvalidStoreError, InvalidStoreState } from "./errors";
|
|
||||||
import { ClientEvent, IStoredClientOpts, MatrixClient, PendingEventOrdering, ResetTimelineCallback } from "./client";
|
import { ClientEvent, IStoredClientOpts, MatrixClient, PendingEventOrdering, ResetTimelineCallback } from "./client";
|
||||||
import {
|
import {
|
||||||
IEphemeral,
|
IEphemeral,
|
||||||
@@ -593,25 +592,6 @@ export class SyncApi {
|
|||||||
await keepaliveProm;
|
await keepaliveProm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Is the lazy loading option different than in previous session?
|
|
||||||
* @param lazyLoadMembers - current options for lazy loading
|
|
||||||
* @returns whether or not the option has changed compared to the previous session */
|
|
||||||
private async wasLazyLoadingToggled(lazyLoadMembers = false): Promise<boolean> {
|
|
||||||
// assume it was turned off before
|
|
||||||
// if we don't know any better
|
|
||||||
let lazyLoadMembersBefore = false;
|
|
||||||
const isStoreNewlyCreated = await this.client.store.isNewlyCreated();
|
|
||||||
if (!isStoreNewlyCreated) {
|
|
||||||
const prevClientOptions = await this.client.store.getClientOptions();
|
|
||||||
if (prevClientOptions) {
|
|
||||||
lazyLoadMembersBefore = !!prevClientOptions.lazyLoadMembers;
|
|
||||||
}
|
|
||||||
return lazyLoadMembersBefore !== lazyLoadMembers;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private shouldAbortSync(error: MatrixError): boolean {
|
private shouldAbortSync(error: MatrixError): boolean {
|
||||||
if (error.errcode === "M_UNKNOWN_TOKEN") {
|
if (error.errcode === "M_UNKNOWN_TOKEN") {
|
||||||
// The logout already happened, we just need to stop.
|
// The logout already happened, we just need to stop.
|
||||||
@@ -649,9 +629,9 @@ export class SyncApi {
|
|||||||
return filter;
|
return filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
private checkLazyLoadStatus = async (): Promise<void> => {
|
private prepareLazyLoadingForSync = async (): Promise<void> => {
|
||||||
debuglog("Checking lazy load status...");
|
debuglog("Prepare lazy loading for sync...");
|
||||||
if (this.opts.lazyLoadMembers && this.client.isGuest()) {
|
if (this.client.isGuest()) {
|
||||||
this.opts.lazyLoadMembers = false;
|
this.opts.lazyLoadMembers = false;
|
||||||
}
|
}
|
||||||
if (this.opts.lazyLoadMembers) {
|
if (this.opts.lazyLoadMembers) {
|
||||||
@@ -661,23 +641,12 @@ export class SyncApi {
|
|||||||
}
|
}
|
||||||
this.opts.filter.setLazyLoadMembers(true);
|
this.opts.filter.setLazyLoadMembers(true);
|
||||||
}
|
}
|
||||||
// need to vape the store when enabling LL and wasn't enabled before
|
|
||||||
debuglog("Checking whether lazy loading has changed in store...");
|
|
||||||
const shouldClear = await this.wasLazyLoadingToggled(this.opts.lazyLoadMembers);
|
|
||||||
if (shouldClear) {
|
|
||||||
this.storeIsInvalid = true;
|
|
||||||
const error = new InvalidStoreError(InvalidStoreState.ToggledLazyLoading, !!this.opts.lazyLoadMembers);
|
|
||||||
this.updateSyncState(SyncState.Error, { error });
|
|
||||||
// bail out of the sync loop now: the app needs to respond to this error.
|
|
||||||
// we leave the state as 'ERROR' which isn't great since this normally means
|
|
||||||
// we're retrying. The client must be stopped before clearing the stores anyway
|
|
||||||
// so the app should stop the client, clear the store and start it again.
|
|
||||||
logger.warn("InvalidStoreError: store is not usable: stopping sync.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.opts.lazyLoadMembers) {
|
if (this.opts.lazyLoadMembers) {
|
||||||
this.syncOpts.crypto?.enableLazyLoading();
|
this.syncOpts.crypto?.enableLazyLoading();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private storeClientOptions = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
debuglog("Storing client options...");
|
debuglog("Storing client options...");
|
||||||
await this.client.storeClientOptions();
|
await this.client.storeClientOptions();
|
||||||
@@ -757,14 +726,16 @@ export class SyncApi {
|
|||||||
// 1) We need to get push rules so we can check if events should bing as we get
|
// 1) We need to get push rules so we can check if events should bing as we get
|
||||||
// them from /sync.
|
// them from /sync.
|
||||||
// 2) We need to get/create a filter which we can use for /sync.
|
// 2) We need to get/create a filter which we can use for /sync.
|
||||||
// 3) We need to check the lazy loading option matches what was used in the
|
// 3) We need to prepare lazy loading for sync
|
||||||
// stored sync. If it doesn't, we can't use the stored sync.
|
// 4) We need to store the client options
|
||||||
|
|
||||||
// Now start the first incremental sync request: this can also
|
// Now start the first incremental sync request: this can also
|
||||||
// take a while so if we set it going now, we can wait for it
|
// take a while so if we set it going now, we can wait for it
|
||||||
// to finish while we process our saved sync data.
|
// to finish while we process our saved sync data.
|
||||||
await this.getPushRules();
|
await this.getPushRules();
|
||||||
await this.checkLazyLoadStatus();
|
await this.prepareLazyLoadingForSync();
|
||||||
|
await this.storeClientOptions();
|
||||||
|
|
||||||
const { filterId, filter } = await this.getFilter();
|
const { filterId, filter } = await this.getFilter();
|
||||||
if (!filter) return; // bail, getFilter failed
|
if (!filter) return; // bail, getFilter failed
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user