fix(sync): Request all labels / folders to avoid paging and missing inbox

This commit is contained in:
Ben Gotow 2015-10-03 23:53:59 -07:00
parent 84c8e2f99d
commit 308c70f53d
5 changed files with 10 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -94,9 +94,9 @@ class NylasSyncWorker
@fetchCollection('threads') @fetchCollection('threads')
if @_account.usesLabels() if @_account.usesLabels()
@fetchCollection('labels') @fetchCollection('labels', {initialPageSize: 1000})
if @_account.usesFolders() if @_account.usesFolders()
@fetchCollection('folders') @fetchCollection('folders', {initialPageSize: 1000})
@fetchCollection('drafts') @fetchCollection('drafts')
@fetchCollection('contacts') @fetchCollection('contacts')
@fetchCollection('calendars') @fetchCollection('calendars')
@ -116,7 +116,10 @@ class NylasSyncWorker
@writeState() @writeState()
@fetchCollectionCount(model) @fetchCollectionCount(model)
@fetchCollectionPage(model, {offset: 0, limit: INITIAL_PAGE_SIZE}) @fetchCollectionPage(model, {
limit: options.initialPageSize ? INITIAL_PAGE_SIZE,
offset: 0
})
fetchCollectionCount: (model) -> fetchCollectionCount: (model) ->
@_api.makeRequest @_api.makeRequest

View file

@ -62,6 +62,10 @@ describe "NylasSyncWorker", ->
expect(modelsRequested).toEqual(['threads', 'labels', 'drafts', 'contacts', 'events']) expect(modelsRequested).toEqual(['threads', 'labels', 'drafts', 'contacts', 'events'])
expect(countsRequested).toEqual(['/threads', '/labels', '/drafts', '/contacts', '/events']) expect(countsRequested).toEqual(['/threads', '/labels', '/drafts', '/contacts', '/events'])
fit "should fetch 1000 labels and folders, to prevent issues where Inbox is not in the first page", ->
labelsRequest = _.find @apiRequests, (r) -> r.model is 'labels'
expect(labelsRequest.params.limit).toBe(1000)
it "should mark incomplete collections as `busy`", -> it "should mark incomplete collections as `busy`", ->
@worker.start() @worker.start()
advanceClock() advanceClock()
@ -102,7 +106,6 @@ describe "NylasSyncWorker", ->
advanceClock(30000); expect(@worker.resumeFetches.callCount).toBe(5) advanceClock(30000); expect(@worker.resumeFetches.callCount).toBe(5)
it "handles the request as a failure if we try and grab labels or folders without an 'inbox'", -> it "handles the request as a failure if we try and grab labels or folders without an 'inbox'", ->
spyOn(@worker, 'resumeFetches').andCallThrough() spyOn(@worker, 'resumeFetches').andCallThrough()
@worker.start() @worker.start()
expect(@worker.resumeFetches.callCount).toBe(1) expect(@worker.resumeFetches.callCount).toBe(1)
@ -113,7 +116,6 @@ describe "NylasSyncWorker", ->
expect(@worker.resumeFetches.callCount).toBe(2) expect(@worker.resumeFetches.callCount).toBe(2)
it "handles the request as a success if we try and grab labels or folders and it includes the 'inbox'", -> it "handles the request as a success if we try and grab labels or folders and it includes the 'inbox'", ->
spyOn(@worker, 'resumeFetches').andCallThrough() spyOn(@worker, 'resumeFetches').andCallThrough()
@worker.start() @worker.start()
expect(@worker.resumeFetches.callCount).toBe(1) expect(@worker.resumeFetches.callCount).toBe(1)

View file

@ -55,7 +55,6 @@ describe "NylasAPI", ->
expect(Actions.postNotification.mostRecentCall.args[0].message).toEqual("Nylas can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please unlink your account and sign in again.") expect(Actions.postNotification.mostRecentCall.args[0].message).toEqual("Nylas can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please unlink your account and sign in again.")
describe "handleModelResponse", -> describe "handleModelResponse", ->
beforeEach -> beforeEach ->
spyOn(DatabaseStore, "persistModels").andCallFake (models) -> spyOn(DatabaseStore, "persistModels").andCallFake (models) ->
Promise.resolve(models) Promise.resolve(models)