Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

chore: remove awareness sync since it's not used (#9563)

Saul-Mirone26fb9d148c38
diff --git a/blocksuite/framework/store/src/model/workspace.ts b/blocksuite/framework/store/src/model/workspace.ts
index 7df46231c5..cd33b5ec0b 100644
--- a/blocksuite/framework/store/src/model/workspace.ts
+++ b/blocksuite/framework/store/src/model/workspace.ts
@@ -1,5 +1,5 @@
import type { Slot } from '@blocksuite/global/utils';
-import type { BlobEngine, DocEngine } from '@blocksuite/sync';
+import type { BlobEngine } from '@blocksuite/sync';
import type * as Y from 'yjs';
import type { Schema } from '../schema/schema.js';
@@ -13,7 +13,6 @@ export interface Workspace {
readonly id: string;
readonly meta: WorkspaceMeta;
readonly idGenerator: IdGenerator;
- readonly docSync: DocEngine;
readonly blobSync: BlobEngine;
readonly awarenessStore: AwarenessStore;
diff --git a/blocksuite/framework/store/src/test/test-doc.ts b/blocksuite/framework/store/src/test/test-doc.ts
index 2af889f745..818e027ffa 100644
--- a/blocksuite/framework/store/src/test/test-doc.ts
+++ b/blocksuite/framework/store/src/test/test-doc.ts
@@ -147,10 +147,6 @@ export class TestDoc implements Doc {
return this._collection;
}
- get docSync() {
- return this.workspace.docSync;
- }
-
get history() {
return this._history;
}
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/messages/slides-renderer.ts b/packages/frontend/core/src/blocksuite/presets/ai/messages/slides-renderer.ts
index b4b65058ef..c6e7413bbe 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/messages/slides-renderer.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/messages/slides-renderer.ts
@@ -226,7 +226,6 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
id: 'SLIDES_PREVIEW',
});
collection.meta.initialize();
- collection.start();
const doc = collection.createDoc();
doc.load(() => {
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/mini-mindmap/mindmap-preview.ts b/packages/frontend/core/src/blocksuite/presets/ai/mini-mindmap/mindmap-preview.ts
index df34c7fae7..ac2a111866 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/mini-mindmap/mindmap-preview.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/mini-mindmap/mindmap-preview.ts
@@ -102,8 +102,6 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
schema,
});
collection.meta.initialize();
- collection.start();
-
const doc = collection.createDoc({ id: 'doc:home' }).load();
const rootId = doc.addBlock('affine:page', {});
const surfaceId = doc.addBlock('affine:surface', {}, rootId);
diff --git a/packages/frontend/core/src/modules/workspace/impls/doc.ts b/packages/frontend/core/src/modules/workspace/impls/doc.ts
index 9dd42a73f2..ce7ed17250 100644
--- a/packages/frontend/core/src/modules/workspace/impls/doc.ts
+++ b/packages/frontend/core/src/modules/workspace/impls/doc.ts
@@ -142,10 +142,6 @@ export class DocImpl implements Doc {
return this._collection;
}
- get docSync() {
- return this.workspace.docSync;
- }
-
get history() {
return this._history;
}
diff --git a/packages/frontend/core/src/modules/workspace/impls/workspace.ts b/packages/frontend/core/src/modules/workspace/impls/workspace.ts
index e633854aab..ef7e32d4bf 100644
--- a/packages/frontend/core/src/modules/workspace/impls/workspace.ts
+++ b/packages/frontend/core/src/modules/workspace/impls/workspace.ts
@@ -17,12 +17,9 @@ import {
type WorkspaceMeta,
} from '@blocksuite/affine/store';
import {
- AwarenessEngine,
BlobEngine,
type BlobSource,
- DocEngine,
MemoryBlobSource,
- NoopDocSource,
} from '@blocksuite/affine/sync';
import { Awareness } from 'y-protocols/awareness.js';
import * as Y from 'yjs';
@@ -61,16 +58,12 @@ export class WorkspaceImpl implements Workspace {
readonly awarenessStore: AwarenessStore;
- readonly awarenessSync: AwarenessEngine;
-
readonly blobSync: BlobEngine;
readonly blockCollections = new Map<string, Doc>();
readonly doc: Y.Doc;
- readonly docSync: DocEngine;
-
readonly id: string;
readonly idGenerator: IdGenerator;
@@ -102,11 +95,8 @@ export class WorkspaceImpl implements Workspace {
});
blobSource = blobSource ?? new MemoryBlobSource();
- const docSource = new NoopDocSource();
const logger = new NoopLogger();
- this.awarenessSync = new AwarenessEngine(this.awarenessStore.awareness, []);
- this.docSync = new DocEngine(this.doc, docSource, [], logger);
this.blobSync = new BlobEngine(blobSource, [], logger);
this.idGenerator = nanoid;
@@ -129,10 +119,10 @@ export class WorkspaceImpl implements Workspace {
this.meta.docMetaUpdated.on(() => this.slots.docListUpdated.emit());
this.meta.docMetaRemoved.on(id => {
- const space = this.getBlockCollection(id);
- if (!space) return;
+ const doc = this._getDoc(id);
+ if (!doc) return;
this.blockCollections.delete(id);
- space.remove();
+ doc.remove();
this.slots.docRemoved.emit(id);
});
}
@@ -141,14 +131,6 @@ export class WorkspaceImpl implements Workspace {
return this.docs.has(docId);
}
- /**
- * Verify that all data has been successfully saved to the primary storage.
- * Return true if the data transfer is complete and it is secure to terminate the synchronization operation.
- */
- canGracefulStop() {
- this.docSync.canGracefulStop();
- }
-
/**
* By default, only an empty doc will be created.
* If the `init` parameter is passed, a `surface`, `note`, and `paragraph` block
@@ -177,23 +159,13 @@ export class WorkspaceImpl implements Workspace {
this.awarenessStore.destroy();
}
- /**
- * Terminate the data sync process forcefully, which may cause data loss.
- * It is advised to invoke `canGracefulStop` before calling this method.
- */
- forceStop() {
- this.docSync.forceStop();
- this.blobSync.stop();
- this.awarenessSync.disconnect();
- }
-
- getBlockCollection(docId: string): Doc | null {
+ private _getDoc(docId: string): Doc | null {
const space = this.docs.get(docId) as Doc | undefined;
return space ?? null;
}
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
- const collection = this.getBlockCollection(docId);
+ const collection = this._getDoc(docId);
return collection?.getBlocks(options) ?? null;
}
@@ -206,31 +178,11 @@ export class WorkspaceImpl implements Workspace {
);
}
- const blockCollection = this.getBlockCollection(docId);
+ const blockCollection = this._getDoc(docId);
if (!blockCollection) return;
blockCollection.dispose();
this.meta.removeDocMeta(docId);
this.blockCollections.delete(docId);
}
-
- /**
- * Start the data sync process
- */
- start() {
- this.docSync.start();
- this.blobSync.start();
- this.awarenessSync.connect();
- }
-
- /**
- * Wait for all data has been successfully saved to the primary storage.
- */
- waitForGracefulStop(abort?: AbortSignal) {
- return this.docSync.waitForGracefulStop(abort);
- }
-
- waitForSynced() {
- return this.docSync.waitForSynced();
- }
}