fix(ios): fix mobile blob storage (#8702)

This commit is contained in:
EYHN
2024-11-05 11:16:00 +00:00
parent c0d802a169
commit 4977055a2e
5 changed files with 60 additions and 37 deletions
@@ -1,6 +1,6 @@
import { useDocMetaHelper } from '@affine/core/components/hooks/use-block-suite-page-meta';
import { useDocCollectionPage } from '@affine/core/components/hooks/use-block-suite-workspace-page';
import { FetchService } from '@affine/core/modules/cloud';
import { FetchService, GraphQLService } from '@affine/core/modules/cloud';
import { DebugLogger } from '@affine/debug';
import type { ListHistoryQuery } from '@affine/graphql';
import { listHistoryQuery, recoverDocMutation } from '@affine/graphql';
@@ -102,11 +102,16 @@ const docCollectionMap = new Map<string, DocCollection>();
// assume the workspace is a cloud workspace since the history feature is only enabled for cloud workspace
const getOrCreateShellWorkspace = (
workspaceId: string,
fetchService: FetchService
fetchService: FetchService,
graphQLService: GraphQLService
) => {
let docCollection = docCollectionMap.get(workspaceId);
if (!docCollection) {
const blobStorage = new CloudBlobStorage(workspaceId, fetchService);
const blobStorage = new CloudBlobStorage(
workspaceId,
fetchService,
graphQLService
);
docCollection = new DocCollection({
id: workspaceId,
blobSources: {
@@ -144,6 +149,7 @@ export const useSnapshotPage = (
ts?: string
) => {
const fetchService = useService(FetchService);
const graphQLService = useService(GraphQLService);
const snapshot = usePageHistory(docCollection.id, pageDocId, ts);
const page = useMemo(() => {
if (!ts) {
@@ -152,7 +158,8 @@ export const useSnapshotPage = (
const pageId = pageDocId + '-' + ts;
const historyShellWorkspace = getOrCreateShellWorkspace(
docCollection.id,
fetchService
fetchService,
graphQLService
);
let page = historyShellWorkspace.getDoc(pageId);
if (!page && snapshot) {
@@ -167,18 +174,19 @@ export const useSnapshotPage = (
}); // must load before applyUpdate
}
return page ?? undefined;
}, [ts, pageDocId, docCollection.id, fetchService, snapshot]);
}, [ts, pageDocId, docCollection.id, fetchService, graphQLService, snapshot]);
useEffect(() => {
const historyShellWorkspace = getOrCreateShellWorkspace(
docCollection.id,
fetchService
fetchService,
graphQLService
);
// apply the rootdoc's update to the current workspace
// this makes sure the page reference links are not deleted ones in the preview
const update = encodeStateAsUpdate(docCollection.doc);
applyUpdate(historyShellWorkspace.doc, update);
}, [docCollection, fetchService]);
}, [docCollection, fetchService, graphQLService]);
return page;
};