From f73a7326662a71836dd4a1258798d4c1475a0c20 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 19 Jan 2016 00:00:00 -0800 Subject: [PATCH] Don't wait for all requests to succeed before displaying results --- src/search-subscription.coffee | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/search-subscription.coffee b/src/search-subscription.coffee index d0ad0adac..f8d726712 100644 --- a/src/search-subscription.coffee +++ b/src/search-subscription.coffee @@ -23,28 +23,26 @@ class SearchSubscription extends MutableQuerySubscription @retrievePage(0) replaceRange: (range) => - @retrievePage(Math.floor(range.start / 100)) + # TODO # Accessing Data retrievePage: (idx) => version = @_version += 1 + resultIds = [] - requests = @_accountIds.map (aid) => + @_accountIds.forEach (aid) => NylasAPI.makeRequest method: 'GET' path: "/threads/search?q=#{encodeURIComponent(@_terms)}" accountId: aid json: true returnsModel: true + .then (threads) => + return unless @_version is version - Promise.all(requests).then (resultArrays) => - return unless @_version is version - resultIds = [] - for resultArray in resultArrays - resultIds = resultIds.concat _.pluck(resultArray, 'id') - - query = DatabaseStore.findAll(Thread).where(id: resultIds).order(Thread.attributes.lastMessageReceivedTimestamp.descending()) - @replaceQuery(query) + resultIds = resultIds.concat _.pluck(threads, 'id') + query = DatabaseStore.findAll(Thread).where(id: resultIds).order(Thread.attributes.lastMessageReceivedTimestamp.descending()) + @replaceQuery(query) module.exports = SearchSubscription