refactor: remove sync binary (#1297)

This commit is contained in:
Himself65
2023-03-03 13:36:42 -06:00
committed by GitHub
parent fd510834ed
commit 296cd215c1
22 changed files with 161 additions and 202 deletions
+9 -18
View File
@@ -1,8 +1,8 @@
import { createAffineProviders } from '../../blocksuite';
import { Unreachable } from '../../components/affine/affine-error-eoundary';
import {
AffineRemoteUnSyncedWorkspace,
RemWorkspaceFlavour,
transformToAffineSyncedWorkspace,
} from '../../shared';
import { apis } from '../../shared/apis';
import { createEmptyBlockSuiteWorkspace } from '../../utils';
@@ -42,26 +42,17 @@ export const fetcher = async (
if (query === QueryKey.getWorkspaces) {
return apis.getWorkspaces().then(workspaces => {
return workspaces.map(workspace => {
const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
workspace.id,
(k: string) =>
// fixme: token could be expired
({ api: '/api/workspace', token: apis.auth.token }[k])
);
const remWorkspace: AffineRemoteUnSyncedWorkspace = {
...workspace,
flavour: RemWorkspaceFlavour.AFFINE,
firstBinarySynced: false,
blockSuiteWorkspace: createEmptyBlockSuiteWorkspace(
workspace.id,
(k: string) =>
// fixme: token could be expired
({ api: '/api/workspace', token: apis.auth.token }[k])
),
syncBinary: async () => {
const binary = await apis.downloadWorkspace(
workspace.id,
workspace.public
);
if (remWorkspace.firstBinarySynced) {
return null;
}
return transformToAffineSyncedWorkspace(remWorkspace, binary);
},
blockSuiteWorkspace,
providers: [...createAffineProviders(blockSuiteWorkspace)],
};
return remWorkspace;
});
+1 -12
View File
@@ -44,9 +44,7 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
await apis.deleteWorkspace({
id: workspace.id,
});
if (workspace.firstBinarySynced) {
workspace.providers.forEach(p => p.cleanup());
}
workspace.providers.forEach(p => p.cleanup());
},
prefetchData: async dataCenter => {
if (localStorage.getItem(kAffineLocal)) {
@@ -74,9 +72,6 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
blockSuiteWorkspace,
providers: [...createAffineProviders(blockSuiteWorkspace)],
flavour: RemWorkspaceFlavour.AFFINE,
syncBinary: async () => {
return { ...affineWorkspace };
},
};
return affineWorkspace;
});
@@ -106,9 +101,6 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
.then(async workspaces => {
const promises = workspaces.map(workspace => {
assertEquals(workspace.flavour, RemWorkspaceFlavour.AFFINE);
if (!workspace.firstBinarySynced) {
return workspace.syncBinary();
}
return workspace;
});
return Promise.all(promises)
@@ -151,9 +143,6 @@ export const AffinePlugin: WorkspacePlugin<RemWorkspaceFlavour.AFFINE> = {
});
},
PageDetail: ({ currentWorkspace, currentPageId }) => {
if (!currentWorkspace.firstBinarySynced) {
return <div>Loading</div>;
}
const page = currentWorkspace.blockSuiteWorkspace.getPage(currentPageId);
if (!page) {
throw new PageNotFoundError(