Skip to content

Commit

Permalink
added debounce for crud upload
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Nov 28, 2023
1 parent 515ed2d commit 346015e
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
logger: Logger.get('PowerSyncStream')
};

const CRUD_UPLOAD_DEBOUNCE_MS = 1000;

export abstract class AbstractStreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener> {
protected _lastSyncedAt: Date | null;
protected options: AbstractStreamingSyncImplementationOptions;
Expand Down Expand Up @@ -86,12 +88,16 @@ export abstract class AbstractStreamingSyncImplementation extends BaseObserver<S
return this.options.adapter.hasCompletedSync();
}

triggerCrudUpload() {
if (!this.syncStatus.connected || this.syncStatus.dataFlowStatus.uploading) {
return;
}
this._uploadAllCrud();
}
triggerCrudUpload = _.debounce(
() => {
if (!this.syncStatus.connected || this.syncStatus.dataFlowStatus.uploading) {
return;
}
this._uploadAllCrud();
},
CRUD_UPLOAD_DEBOUNCE_MS,
{ trailing: true }
);

protected async _uploadAllCrud(): Promise<void> {
return this.obtainLock({
Expand Down

0 comments on commit 346015e

Please sign in to comment.