mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-29 18:12:30 +03:00
fix: duplicate api call for cloud workspace (#928)
This commit is contained in:
parent
718322ec65
commit
5a93b26cc3
@ -45,6 +45,7 @@ export class AffineProvider extends BaseProvider {
|
||||
private _apis: Apis;
|
||||
private _channel?: WebsocketClient;
|
||||
// private _idbMap: Map<string, IndexedDBProvider> = new Map();
|
||||
private _workspaceLoadingQueue: Set<string> = new Set();
|
||||
|
||||
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
||||
super(params);
|
||||
@ -145,11 +146,13 @@ export class AffineProvider extends BaseProvider {
|
||||
// update workspaces
|
||||
this._workspaces.update(id, workspace);
|
||||
} else {
|
||||
const workspaceUnit = await loadWorkspaceUnit(
|
||||
{ id, ...workspace },
|
||||
this._apis
|
||||
);
|
||||
newlyCreatedWorkspaces.push(workspaceUnit);
|
||||
if (!this._workspaceLoadingQueue.has(id)) {
|
||||
const workspaceUnit = await loadWorkspaceUnit(
|
||||
{ id, ...workspace },
|
||||
this._apis
|
||||
);
|
||||
newlyCreatedWorkspaces.push(workspaceUnit);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`[log warn] ${id} name is empty`);
|
||||
@ -204,6 +207,7 @@ export class AffineProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
override async warpWorkspace(workspace: BlocksuiteWorkspace) {
|
||||
// FIXME: if add indexedDB cache in the future, can remove following line.
|
||||
await this._applyCloudUpdates(workspace);
|
||||
const { room } = workspace;
|
||||
assert(room);
|
||||
@ -234,6 +238,7 @@ export class AffineProvider extends BaseProvider {
|
||||
const workspacesList = await this._apis.getWorkspaces();
|
||||
const workspaceUnits = await Promise.all(
|
||||
workspacesList.map(w => {
|
||||
this._workspaceLoadingQueue.add(w.id);
|
||||
return loadWorkspaceUnit(
|
||||
{
|
||||
id: w.id,
|
||||
@ -246,7 +251,9 @@ export class AffineProvider extends BaseProvider {
|
||||
syncMode: 'core',
|
||||
},
|
||||
this._apis
|
||||
);
|
||||
).finally(() => {
|
||||
this._workspaceLoadingQueue.delete(w.id);
|
||||
});
|
||||
})
|
||||
);
|
||||
this._workspaces.add(workspaceUnits);
|
||||
|
Loading…
Reference in New Issue
Block a user