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

This commit is contained in:
Saul-Mirone
2025-01-07 06:12:08 +00:00
parent 0d2eb64817
commit 26fb9d148c
6 changed files with 7 additions and 67 deletions

View File

@@ -1,5 +1,5 @@
import type { Slot } from '@blocksuite/global/utils'; 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 * as Y from 'yjs';
import type { Schema } from '../schema/schema.js'; import type { Schema } from '../schema/schema.js';
@@ -13,7 +13,6 @@ export interface Workspace {
readonly id: string; readonly id: string;
readonly meta: WorkspaceMeta; readonly meta: WorkspaceMeta;
readonly idGenerator: IdGenerator; readonly idGenerator: IdGenerator;
readonly docSync: DocEngine;
readonly blobSync: BlobEngine; readonly blobSync: BlobEngine;
readonly awarenessStore: AwarenessStore; readonly awarenessStore: AwarenessStore;

View File

@@ -147,10 +147,6 @@ export class TestDoc implements Doc {
return this._collection; return this._collection;
} }
get docSync() {
return this.workspace.docSync;
}
get history() { get history() {
return this._history; return this._history;
} }

View File

@@ -226,7 +226,6 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
id: 'SLIDES_PREVIEW', id: 'SLIDES_PREVIEW',
}); });
collection.meta.initialize(); collection.meta.initialize();
collection.start();
const doc = collection.createDoc(); const doc = collection.createDoc();
doc.load(() => { doc.load(() => {

View File

@@ -102,8 +102,6 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
schema, schema,
}); });
collection.meta.initialize(); collection.meta.initialize();
collection.start();
const doc = collection.createDoc({ id: 'doc:home' }).load(); const doc = collection.createDoc({ id: 'doc:home' }).load();
const rootId = doc.addBlock('affine:page', {}); const rootId = doc.addBlock('affine:page', {});
const surfaceId = doc.addBlock('affine:surface', {}, rootId); const surfaceId = doc.addBlock('affine:surface', {}, rootId);

View File

@@ -142,10 +142,6 @@ export class DocImpl implements Doc {
return this._collection; return this._collection;
} }
get docSync() {
return this.workspace.docSync;
}
get history() { get history() {
return this._history; return this._history;
} }

View File

@@ -17,12 +17,9 @@ import {
type WorkspaceMeta, type WorkspaceMeta,
} from '@blocksuite/affine/store'; } from '@blocksuite/affine/store';
import { import {
AwarenessEngine,
BlobEngine, BlobEngine,
type BlobSource, type BlobSource,
DocEngine,
MemoryBlobSource, MemoryBlobSource,
NoopDocSource,
} from '@blocksuite/affine/sync'; } from '@blocksuite/affine/sync';
import { Awareness } from 'y-protocols/awareness.js'; import { Awareness } from 'y-protocols/awareness.js';
import * as Y from 'yjs'; import * as Y from 'yjs';
@@ -61,16 +58,12 @@ export class WorkspaceImpl implements Workspace {
readonly awarenessStore: AwarenessStore; readonly awarenessStore: AwarenessStore;
readonly awarenessSync: AwarenessEngine;
readonly blobSync: BlobEngine; readonly blobSync: BlobEngine;
readonly blockCollections = new Map<string, Doc>(); readonly blockCollections = new Map<string, Doc>();
readonly doc: Y.Doc; readonly doc: Y.Doc;
readonly docSync: DocEngine;
readonly id: string; readonly id: string;
readonly idGenerator: IdGenerator; readonly idGenerator: IdGenerator;
@@ -102,11 +95,8 @@ export class WorkspaceImpl implements Workspace {
}); });
blobSource = blobSource ?? new MemoryBlobSource(); blobSource = blobSource ?? new MemoryBlobSource();
const docSource = new NoopDocSource();
const logger = new NoopLogger(); 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.blobSync = new BlobEngine(blobSource, [], logger);
this.idGenerator = nanoid; this.idGenerator = nanoid;
@@ -129,10 +119,10 @@ export class WorkspaceImpl implements Workspace {
this.meta.docMetaUpdated.on(() => this.slots.docListUpdated.emit()); this.meta.docMetaUpdated.on(() => this.slots.docListUpdated.emit());
this.meta.docMetaRemoved.on(id => { this.meta.docMetaRemoved.on(id => {
const space = this.getBlockCollection(id); const doc = this._getDoc(id);
if (!space) return; if (!doc) return;
this.blockCollections.delete(id); this.blockCollections.delete(id);
space.remove(); doc.remove();
this.slots.docRemoved.emit(id); this.slots.docRemoved.emit(id);
}); });
} }
@@ -141,14 +131,6 @@ export class WorkspaceImpl implements Workspace {
return this.docs.has(docId); 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. * By default, only an empty doc will be created.
* If the `init` parameter is passed, a `surface`, `note`, and `paragraph` block * If the `init` parameter is passed, a `surface`, `note`, and `paragraph` block
@@ -177,23 +159,13 @@ export class WorkspaceImpl implements Workspace {
this.awarenessStore.destroy(); this.awarenessStore.destroy();
} }
/** private _getDoc(docId: string): Doc | null {
* 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 {
const space = this.docs.get(docId) as Doc | undefined; const space = this.docs.get(docId) as Doc | undefined;
return space ?? null; return space ?? null;
} }
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null { getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
const collection = this.getBlockCollection(docId); const collection = this._getDoc(docId);
return collection?.getBlocks(options) ?? null; 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; if (!blockCollection) return;
blockCollection.dispose(); blockCollection.dispose();
this.meta.removeDocMeta(docId); this.meta.removeDocMeta(docId);
this.blockCollections.delete(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();
}
} }