Skip to content

Commit

Permalink
NDNts-aux snapshot v1.1 (#10)
Browse files Browse the repository at this point in the history
* Configurable "snapshot topic" specified
* Expose snapshot config to workspace.create()
* Default snapshot interval changed from 10 to 100.
  • Loading branch information
CAWorks-ChrisA authored Oct 20, 2024
1 parent edcff4c commit 9f4a535
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/adaptors/yjs-ndn-adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Workspace implements AsyncDisposable {
createNewDoc?: () => Promise<void>;
useBundler?: boolean;
groupKeyBits?: Uint8Array;
snapshotInterval?: number;
}) {
// Always init a new one, and then load.
if (opts.createNewDoc) {
Expand All @@ -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()),
Expand Down

0 comments on commit 9f4a535

Please sign in to comment.