diff --git a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee index 9ca01b726..de5ebb404 100644 --- a/internal_packages/worker-sync/lib/nylas-sync-worker.coffee +++ b/internal_packages/worker-sync/lib/nylas-sync-worker.coffee @@ -132,6 +132,7 @@ class NylasSyncWorker @_resumeTimer.start() fetchCollectionPage: (model, params = {}) -> + requestStartTime = Date.now() requestOptions = error: (err) => return if @_terminated @@ -143,7 +144,8 @@ class NylasSyncWorker lastReceivedIndex = params.offset + json.length if json.length is params.limit nextParams = _.extend({}, params, {offset: lastReceivedIndex}) - @fetchCollectionPage(model, nextParams) + nextDelay = Math.max(0, 1500 - (Date.now() - requestStartTime)) + setTimeout(( => @fetchCollectionPage(model, nextParams)), nextDelay) @updateTransferState(model, {fetched: lastReceivedIndex}) else @updateTransferState(model, {fetched: lastReceivedIndex, busy: false, complete: true}) diff --git a/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee b/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee index f9a044172..85be8d5fc 100644 --- a/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee +++ b/internal_packages/worker-sync/spec/nylas-sync-worker-spec.coffee @@ -170,6 +170,7 @@ describe "NylasSyncWorker", -> models = [] models.push(new Thread) for i in [0..(pageSize-1)] @request.requestOptions.success(models) + advanceClock(2000) expect(@apiRequests.length).toBe(1) expect(@apiRequests[0].params).toEqual limit: pageSize,