diff --git a/spec/stores/task-queue-spec.coffee b/spec/stores/task-queue-spec.coffee index 0080d742e..c7b92779d 100644 --- a/spec/stores/task-queue-spec.coffee +++ b/spec/stores/task-queue-spec.coffee @@ -12,9 +12,6 @@ TaskRegistry = require('../../src/task-registry').default KillsTaskA, BlockedByTaskA, BlockingTask, - Task100, - Task200, - Task300, TaskAA, TaskBB} = require('./task-subclass') @@ -38,7 +35,6 @@ describe "TaskQueue", -> @unstartedTask = makeUnstartedTask(new Task()) @processingTask = makeProcessing(new Task()) @retryInFutureTask = makeRetryInFuture(new Task()) - TaskQueue._runLocalPromise = Promise.resolve() afterEach -> # Flush any throttled or debounced updates @@ -103,63 +99,8 @@ describe "TaskQueue", -> expect(TaskQueue._queue.length).toBe(1) it "immediately calls runLocal", -> - waitsForPromise => - TaskQueue.enqueue(@unstartedTask).then => - expect(@unstartedTask.runLocal).toHaveBeenCalled() - - it "correctly orders two task queues one after another", -> - t1 = new Task100() - t2 = new Task200() - t2b = new Task200() - t3 = new Task300() - spyOn(t1, "runLocal").andCallThrough() - spyOn(t2, "runLocal").andCallThrough() - spyOn(t2b, "runLocal").andCallThrough() - spyOn(t3, "runLocal").andCallThrough() - - TaskQueue.enqueue(t1) - advanceClock(1) # Need to tick past the first Promise.resolve() - expect(t1.runLocal).toHaveBeenCalled() - expect(TaskQueue._queue.length).toBe(0) - - TaskQueue.enqueue(t2) - # Blocked waiting for t1 - expect(t2.runLocal).not.toHaveBeenCalled() - expect(TaskQueue._queue.length).toBe(0) - - advanceClock(11) # Not enough for Task100's performLocal to clear - expect(t1.runLocal).toHaveBeenCalled() - expect(t2.runLocal).not.toHaveBeenCalled() # Still blocked on t1 - expect(TaskQueue._queue.length).toBe(0) - - # This clears Task100's timeout. Note performRemote has a 1000ms - # timeout. - advanceClock(100) # Clears timeouts - advanceClock(1) # Clears remaining Promises - # T1 performLocal is done now! - expect(TaskQueue._queue.length).toBe(1) - expect(TaskQueue._queue[0]).toBe(t1) # T1 on the queue - expect(t2.runLocal).toHaveBeenCalled() #T2 unblocked - - # This clears Task200's timeout. Note performRemote has a 1000ms - # timeout. - advanceClock(200) # Clears timeouts - advanceClock(1) # Clears remaining promises - expect(TaskQueue._queue.length).toBe(2) - expect(TaskQueue._queue[1]).toBe(t2) # T2 on the queue - - # All previous promise should have been resolved, meaning we only - # have to wait 1 tick for the freshly cleared queue to restart. - TaskQueue.enqueue(t3) - advanceClock(1) - expect(t3.runLocal).toHaveBeenCalled() - - advanceClock(300) # Clears t3 performLocal - advanceClock(1) # Clears remaining promises - expect(TaskQueue._queue.length).toBe(3) - expect(TaskQueue._queue[2]).toBe(t3) - - advanceClock(1500) # Clears Task300 off the queue + TaskQueue.enqueue(@unstartedTask) + expect(@unstartedTask.runLocal).toHaveBeenCalled() it "notifies the queue should be processed", -> spyOn(TaskQueue, "_processQueue").andCallThrough() diff --git a/spec/stores/task-subclass.es6 b/spec/stores/task-subclass.es6 index 24554621d..7c3fd5061 100644 --- a/spec/stores/task-subclass.es6 +++ b/spec/stores/task-subclass.es6 @@ -56,30 +56,3 @@ export class OKTask extends Task { export class BadTask extends Task { performRemote() { return Promise.resolve('lalal') } } - -export class Task100 extends Task { - performLocal() { - return new Promise((resolve) => setTimeout(resolve, 100)) - } - performRemote() { - return new Promise((resolve) => setTimeout(resolve, 1000)) - } -} - -export class Task200 extends Task { - performLocal() { - return new Promise((resolve) => setTimeout(resolve, 200)) - } - performRemote() { - return new Promise((resolve) => setTimeout(resolve, 1000)) - } -} - -export class Task300 extends Task { - performLocal() { - return new Promise((resolve) => setTimeout(resolve, 300)) - } - performRemote() { - return new Promise((resolve) => setTimeout(resolve, 1000)) - } -} diff --git a/spec/tasks/syncback-draft-task-spec.es6 b/spec/tasks/syncback-draft-task-spec.es6 index 59f498ab5..f5435d689 100644 --- a/spec/tasks/syncback-draft-task-spec.es6 +++ b/spec/tasks/syncback-draft-task-spec.es6 @@ -99,7 +99,6 @@ describe('SyncbackDraftTask', function syncbackDraftTask() { spyOn(this.taskC, "runLocal").andReturn(Promise.resolve()); TaskQueue.enqueue(this.taskC); - advanceClock(10) // Note that taskB is gone, taskOther was untouched, and taskC was // added. diff --git a/spec/time-override.coffee b/spec/time-override.coffee index b68cf55db..e301c6add 100644 --- a/spec/time-override.coffee +++ b/spec/time-override.coffee @@ -88,7 +88,7 @@ class TimeOverride @_fakeSetInterval = (callback, ms) => id = ++@intervalCount - action = => + action = -> callback() @intervalTimeouts[id] = @_fakeSetTimeout(action, ms) @intervalTimeouts[id] = @_fakeSetTimeout(action, ms) diff --git a/src/flux/models/contact.coffee b/src/flux/models/contact.coffee index 60a6cc616..c2d7f70da 100644 --- a/src/flux/models/contact.coffee +++ b/src/flux/models/contact.coffee @@ -111,11 +111,6 @@ class Contact extends Model account = AccountStore.accountForEmail(@email) return account? - hasSameDomainAsMe: -> - for myEmail in AccountStore.emailAddresses() - return true if Utils.emailsHaveSameDomain(@email, myEmail) - return false - isMePhrase: ({includeAccountLabel, forceAccountLabel} = {}) -> account = AccountStore.accountForEmail(@email) return null unless account diff --git a/src/flux/stores/account-store.coffee b/src/flux/stores/account-store.coffee index 07ad23456..85b527f06 100644 --- a/src/flux/stores/account-store.coffee +++ b/src/flux/stores/account-store.coffee @@ -242,11 +242,6 @@ class AccountStore extends NylasStore return @accountForId(alias.accountId) return null - emailAddresses: -> - addresses = _.pluck((@accounts() ? []), "emailAddress") - addresses = addresses.concat(_.pluck((@aliases() ? [])), "email") - return addresses - # Public: Returns the {Account} for the given account id, or null. accountForId: (id) => @_cachedGetter "accountForId:#{id}", => _.findWhere(@_accounts, {id}) diff --git a/src/flux/stores/task-queue.coffee b/src/flux/stores/task-queue.coffee index 6abfbc3e8..788dcf23f 100644 --- a/src/flux/stores/task-queue.coffee +++ b/src/flux/stores/task-queue.coffee @@ -77,8 +77,6 @@ class TaskQueue @_updatePeriodicallyTimeout = null @_currentSequentialId = Date.now() - @_runLocalPromise = Promise.resolve() - @_restoreQueue() @listenTo Actions.queueTask, @enqueue @@ -139,25 +137,9 @@ class TaskQueue task.sequentialId = ++@_currentSequentialId @_dequeueObsoleteTasks(task) - - doRunLocal = => - task.runLocal().then => - @_queue.push(task) - @_updateSoon() - return Promise.resolve() - - # NOTE: runLocal now runs synchronously so when people build - # `performLocal` methods they can assume the entire set is atomic. - # `performLocal` very frequently has numerous reads and sets to the - # database and we don't want simultaneous tasks to make those reads - # and sets not atomic. While users could wrap their entire - # performLocals in Database transaction blocks, it's common to forget - # to do this and it will still block other tasks from accessing the - # database. - if !@_runLocalPromise.isPending() - # Reset to prevent memory leak of chain. - @_runLocalPromise = Promise.resolve() - @_runLocalPromise = @_runLocalPromise.then(doRunLocal) + task.runLocal().then => + @_queue.push(task) + @_updateSoon() enqueueUndoOfTaskId: (taskId) => task = _.findWhere(@_queue, {id: taskId})