Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer downstream replication #15

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/replication-protocol/downstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any
*/
let lastTimeMasterChangesRequested: number = -1;
async function downstreamResyncOnce() {
if (state.input.forkInstance.options.deferReplication) {
await new Promise((resolve) => {
// eslint-disable-next-line no-console
console.debug(`RxDB: defer downstream replication for ${state.input.forkInstance.collectionName} by ${state.input.forkInstance.options.deferReplication}ms`);
setTimeout(resolve, state.input.forkInstance.options.deferReplication);
});
}
// eslint-disable-next-line no-console
console.time(`RxDB: downstream replication ${state.input.forkInstance.collectionName}`);
state.stats.down.downstreamResyncOnce = state.stats.down.downstreamResyncOnce + 1;
if (state.events.canceled.getValue()) {
return;
Expand Down Expand Up @@ -191,6 +200,8 @@ export async function startReplicationDownstream<RxDocType, CheckpointType = any

}
await Promise.all(promises);
// eslint-disable-next-line no-console
console.timeEnd(`RxDB: downstream replication ${state.input.forkInstance.collectionName}`);
}


Expand Down
Loading