From 765d9f30fc5be75b97e3254d37a6b57fbc341582 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Thu, 28 Apr 2016 15:53:29 -0700 Subject: [PATCH] fix(thread-list): Don't rely on `zip` since it can become off-by-one forever --- .../thread-list/lib/thread-list-data-source.coffee | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal_packages/thread-list/lib/thread-list-data-source.coffee b/internal_packages/thread-list/lib/thread-list-data-source.coffee index 2d021f31e..9da612628 100644 --- a/internal_packages/thread-list/lib/thread-list-data-source.coffee +++ b/internal_packages/thread-list/lib/thread-list-data-source.coffee @@ -18,13 +18,15 @@ _flatMapJoiningMessages = ($threadsResultSet) => # we make a single database query and load /all/ the message metadata for # the new threads at once. (This is a performance optimization -it's about # ~80msec faster than making 100 queries for 100 new thread ids separately.) - Rx.Observable.zip([ - $threadsResultSet, - $threadsResultSet.flatMapLatest (threadsResultSet) => + $threadsResultSet.flatMapLatest (threadsResultSet) => missingIds = threadsResultSet.ids().filter (id) -> not $messagesResultSets[id] - return Rx.Observable.from([[]]) if missingIds.length is 0 - Rx.Observable.fromPromise(DatabaseStore.findAll(Message, threadId: missingIds)) - ]) + if missingIds.length is 0 + promise = Promise.resolve([threadsResultSet, []]) + else + promise = DatabaseStore.findAll(Message, threadId: missingIds).then (messages) => + Promise.resolve([threadsResultSet, messages]) + + return Rx.Observable.fromPromise(promise) # 3. when that finishes, we group the loaded messsages by threadId and create # the missing observables. Creating a query subscription would normally load