feat: disable local cache of affine provider

This commit is contained in:
MingLiang Wang 2023-01-09 17:27:08 +08:00
parent 0b5cc1beda
commit d10affb413

View File

@ -21,7 +21,7 @@ import { varStorage as storage } from 'lib0/storage';
import assert from 'assert'; import assert from 'assert';
import { getAuthorizer } from './apis/token'; import { getAuthorizer } from './apis/token';
import { WebsocketProvider } from './sync'; import { WebsocketProvider } from './sync';
import { IndexedDBProvider } from '../indexeddb'; // import { IndexedDBProvider } from '../local/indexeddb';
import { getDefaultHeadImgBlob } from '../../utils'; import { getDefaultHeadImgBlob } from '../../utils';
import { getUserByEmail } from './apis/user'; import { getUserByEmail } from './apis/user';
@ -32,7 +32,7 @@ export class AffineProvider extends BaseProvider {
private readonly _authorizer = getAuthorizer(); private readonly _authorizer = getAuthorizer();
private _user: User | undefined = undefined; private _user: User | undefined = undefined;
private _wsMap: Map<string, WebsocketProvider> = new Map(); private _wsMap: Map<string, WebsocketProvider> = new Map();
private _idbMap: Map<string, IndexedDBProvider> = new Map(); // private _idbMap: Map<string, IndexedDBProvider> = new Map();
constructor(params: ProviderConstructorParams) { constructor(params: ProviderConstructorParams) {
super(params); super(params);
@ -197,7 +197,7 @@ export class AffineProvider extends BaseProvider {
public override async deleteWorkspace(id: string): Promise<void> { public override async deleteWorkspace(id: string): Promise<void> {
await this.closeWorkspace(id); await this.closeWorkspace(id);
IndexedDBProvider.delete(id); // IndexedDBProvider.delete(id);
await deleteWorkspace({ id }); await deleteWorkspace({ id });
this._workspaces.remove(id); this._workspaces.remove(id);
} }
@ -217,8 +217,8 @@ export class AffineProvider extends BaseProvider {
} }
public override async closeWorkspace(id: string) { public override async closeWorkspace(id: string) {
const idb = this._idbMap.get(id); // const idb = this._idbMap.get(id);
idb?.destroy(); // idb?.destroy();
const ws = this._wsMap.get(id); const ws = this._wsMap.get(id);
ws?.disconnect(); ws?.disconnect();
} }
@ -236,14 +236,15 @@ export class AffineProvider extends BaseProvider {
} }
public override async linkLocal(workspace: Workspace) { public override async linkLocal(workspace: Workspace) {
assert(workspace.room);
let idb = this._idbMap.get(workspace.room);
idb?.destroy();
idb = new IndexedDBProvider(workspace.room, workspace.doc);
this._idbMap.set(workspace.room, idb);
await idb.whenSynced;
this._logger('Local data loaded');
return workspace; return workspace;
// assert(workspace.room);
// let idb = this._idbMap.get(workspace.room);
// idb?.destroy();
// idb = new IndexedDBProvider(workspace.room, workspace.doc);
// this._idbMap.set(workspace.room, idb);
// await idb.whenSynced;
// this._logger('Local data loaded');
// return workspace;
} }
public override async createWorkspace( public override async createWorkspace(