mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 15:26:59 +08:00
fix(core): data loss on enable cloud (#8452)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||||
import { assertEquals } from '@blocksuite/affine/global/utils';
|
import { assertEquals } from '@blocksuite/affine/global/utils';
|
||||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
import { applyUpdate } from 'yjs';
|
||||||
|
|
||||||
import { Service } from '../../../framework';
|
import { Service } from '../../../framework';
|
||||||
import { transformWorkspaceDBLocalToCloud } from '../../db';
|
import { transformWorkspaceDBLocalToCloud } from '../../db';
|
||||||
@@ -28,21 +28,23 @@ export class WorkspaceTransformService extends Service {
|
|||||||
): Promise<WorkspaceMetadata> => {
|
): Promise<WorkspaceMetadata> => {
|
||||||
assertEquals(local.flavour, WorkspaceFlavour.LOCAL);
|
assertEquals(local.flavour, WorkspaceFlavour.LOCAL);
|
||||||
|
|
||||||
await local.engine.waitForDocSynced();
|
const localDocStorage = local.engine.doc.storage.behavior;
|
||||||
|
|
||||||
const newMetadata = await this.factory.create(
|
const newMetadata = await this.factory.create(
|
||||||
WorkspaceFlavour.AFFINE_CLOUD,
|
WorkspaceFlavour.AFFINE_CLOUD,
|
||||||
async (docCollection, blobStorage, docStorage) => {
|
async (docCollection, blobStorage, docStorage) => {
|
||||||
applyUpdate(
|
const rootDocBinary = await localDocStorage.doc.get(
|
||||||
docCollection.doc,
|
local.docCollection.doc.guid
|
||||||
encodeStateAsUpdate(local.docCollection.doc)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const subdoc of local.docCollection.doc.getSubdocs()) {
|
if (rootDocBinary) {
|
||||||
for (const newSubdoc of docCollection.doc.getSubdocs()) {
|
applyUpdate(docCollection.doc, rootDocBinary);
|
||||||
if (newSubdoc.guid === subdoc.guid) {
|
}
|
||||||
applyUpdate(newSubdoc, encodeStateAsUpdate(subdoc));
|
|
||||||
}
|
for (const subdoc of docCollection.doc.getSubdocs()) {
|
||||||
|
const subdocBinary = await localDocStorage.doc.get(subdoc.guid);
|
||||||
|
if (subdocBinary) {
|
||||||
|
applyUpdate(subdoc, subdocBinary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ export class WorkspaceTransformService extends Service {
|
|||||||
await transformWorkspaceDBLocalToCloud(
|
await transformWorkspaceDBLocalToCloud(
|
||||||
local.id,
|
local.id,
|
||||||
docCollection.id,
|
docCollection.id,
|
||||||
local.engine.doc.storage.behavior,
|
localDocStorage,
|
||||||
docStorage,
|
docStorage,
|
||||||
accountId
|
accountId
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user