Skip to content

Commit 9f4a535

Browse files
NDNts-aux snapshot v1.1 (#10)
* Configurable "snapshot topic" specified * Expose snapshot config to workspace.create() * Default snapshot interval changed from 10 to 100.
1 parent edcff4c commit 9f4a535

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/adaptors/yjs-ndn-adaptor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export class NdnSvsAdaptor {
3434
public syncAgent: SyncAgent,
3535
public readonly doc: Y.Doc,
3636
public readonly topic: string,
37-
public readonly snapshotTopic: string = 'snapshot',
38-
public readonly snapshotFrequency: number = 10,
3937
useBundler: boolean = false,
38+
public readonly snapshotInterval: number = 100,
39+
public readonly snapshotTopic: string = 'snapshot',
4040
) {
4141
syncAgent.register('update', topic, (content) => this.handleSyncUpdate(content));
4242
syncAgent.register('blob', snapshotTopic, (content) => this.handleSnapshotUpdate(content));
@@ -116,7 +116,7 @@ export class NdnSvsAdaptor {
116116
count += seq;
117117
}
118118

119-
if (count % this.snapshotFrequency == 0) {
119+
if (count % this.snapshotInterval == 0) {
120120
const encodedSV = Encoder.encode(stateVector);
121121

122122
// NOTE: The following code depend on snapshot naming convention to work.
@@ -130,7 +130,7 @@ export class NdnSvsAdaptor {
130130
const content = Y.encodeStateAsUpdate(this.doc);
131131
// its already in UInt8Array (binary), transporting currently without any additional encoding.
132132
// use syncAgent's blob and publish mechanism
133-
await this.syncAgent.publishBlob('snapshot', content, snapshotName, true);
133+
await this.syncAgent.publishBlob(this.snapshotTopic, content, snapshotName, true);
134134

135135
// NOTE: The following code depend on snapshot naming convention to work.
136136
// Verify this part if there's a change in naming convention.

src/workspace/workspace.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class Workspace implements AsyncDisposable {
2828
createNewDoc?: () => Promise<void>;
2929
useBundler?: boolean;
3030
groupKeyBits?: Uint8Array;
31+
snapshotInterval?: number;
3132
}) {
3233
// Always init a new one, and then load.
3334
if (opts.createNewDoc) {
@@ -54,6 +55,7 @@ export class Workspace implements AsyncDisposable {
5455
opts.rootDoc,
5556
'doc',
5657
opts.useBundler ?? false,
58+
opts.snapshotInterval ?? 100,
5759
);
5860
const yjsSnapshotMgr = new YjsStateManager(
5961
() => encodeSyncState(syncAgent!.getUpdateSyncSV()),

0 commit comments

Comments
 (0)