Skip to content

Commit fb454e1

Browse files
committed
throttle syncdoc snapshot
1 parent 8e89f32 commit fb454e1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/packages/sync/editor/generic/sync-doc.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ export class SyncDoc extends EventEmitter {
15821582
}
15831583
assertDefined(this.patch_list);
15841584
if (init.size == null) {
1585-
// don't crash but warn at least.
1585+
// don't crash but warn at least.
15861586
console.warn("SYNC BUG -- init.size must be defined", { init });
15871587
}
15881588
if (
@@ -2364,9 +2364,14 @@ export class SyncDoc extends EventEmitter {
23642364
});
23652365

23662366
// Have a snapshot every this.snapshot_interval patches, except
2367-
// for the very last interval.
2368-
private snapshotIfNecessary = async (): Promise<void> => {
2369-
if (this.get_state() !== "ready") return;
2367+
// for the very last interval. Throttle so we don't try to make
2368+
// snapshots too frequently, as making them is always optional and
2369+
// now part of the UI.
2370+
private snapshotIfNecessary = throttle(async (): Promise<void> => {
2371+
if (this.get_state() !== "ready") {
2372+
// especially important due to throttle
2373+
return;
2374+
}
23702375
const dbg = this.dbg("snapshotIfNecessary");
23712376
const max_size = Math.floor(1.2 * MAX_FILE_SIZE_MB * 1000000);
23722377
const interval = this.snapshot_interval;
@@ -2390,7 +2395,7 @@ export class SyncDoc extends EventEmitter {
23902395
} else {
23912396
dbg("no need to make a snapshot yet");
23922397
}
2393-
};
2398+
}, 60000);
23942399

23952400
/*- x - patch object
23962401
- patch: if given will be used as an actual patch

0 commit comments

Comments
 (0)