From 9f4a535f024062f99e9d103f33f9de0681c582e8 Mon Sep 17 00:00:00 2001 From: Chris A Date: Sat, 19 Oct 2024 18:25:39 -0700 Subject: [PATCH] NDNts-aux snapshot v1.1 (#10) * Configurable "snapshot topic" specified * Expose snapshot config to workspace.create() * Default snapshot interval changed from 10 to 100. --- src/adaptors/yjs-ndn-adaptor.ts | 8 ++++---- src/workspace/workspace.ts | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/adaptors/yjs-ndn-adaptor.ts b/src/adaptors/yjs-ndn-adaptor.ts index 813529c..85e2062 100644 --- a/src/adaptors/yjs-ndn-adaptor.ts +++ b/src/adaptors/yjs-ndn-adaptor.ts @@ -34,9 +34,9 @@ export class NdnSvsAdaptor { public syncAgent: SyncAgent, public readonly doc: Y.Doc, public readonly topic: string, - public readonly snapshotTopic: string = 'snapshot', - public readonly snapshotFrequency: number = 10, useBundler: boolean = false, + public readonly snapshotInterval: number = 100, + public readonly snapshotTopic: string = 'snapshot', ) { syncAgent.register('update', topic, (content) => this.handleSyncUpdate(content)); syncAgent.register('blob', snapshotTopic, (content) => this.handleSnapshotUpdate(content)); @@ -116,7 +116,7 @@ export class NdnSvsAdaptor { count += seq; } - if (count % this.snapshotFrequency == 0) { + if (count % this.snapshotInterval == 0) { const encodedSV = Encoder.encode(stateVector); // NOTE: The following code depend on snapshot naming convention to work. @@ -130,7 +130,7 @@ export class NdnSvsAdaptor { const content = Y.encodeStateAsUpdate(this.doc); // its already in UInt8Array (binary), transporting currently without any additional encoding. // use syncAgent's blob and publish mechanism - await this.syncAgent.publishBlob('snapshot', content, snapshotName, true); + await this.syncAgent.publishBlob(this.snapshotTopic, content, snapshotName, true); // NOTE: The following code depend on snapshot naming convention to work. // Verify this part if there's a change in naming convention. diff --git a/src/workspace/workspace.ts b/src/workspace/workspace.ts index 884b9f4..7ecee38 100644 --- a/src/workspace/workspace.ts +++ b/src/workspace/workspace.ts @@ -28,6 +28,7 @@ export class Workspace implements AsyncDisposable { createNewDoc?: () => Promise; useBundler?: boolean; groupKeyBits?: Uint8Array; + snapshotInterval?: number; }) { // Always init a new one, and then load. if (opts.createNewDoc) { @@ -54,6 +55,7 @@ export class Workspace implements AsyncDisposable { opts.rootDoc, 'doc', opts.useBundler ?? false, + opts.snapshotInterval ?? 100, ); const yjsSnapshotMgr = new YjsStateManager( () => encodeSyncState(syncAgent!.getUpdateSyncSV()),