mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
fix(sync-worker): Never paginate faster than 1 page per 1.5sec
This should prevent us from flooding the app with contacts (/contacts responds very quickly). Fixes T3475
This commit is contained in:
parent
345dd941a3
commit
041950e014
2 changed files with 4 additions and 1 deletions
|
@ -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})
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue