From 2c815390420f8dc59be24c0f77bc7c1476c70dbf Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 24 May 2017 14:16:34 -0700 Subject: [PATCH] A guard to prevent infinite loops in fetching of conversation FREEBIE --- js/models/messages.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/models/messages.js b/js/models/messages.js index 46e9b1cb6d..1238d8ece4 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -541,6 +541,7 @@ if (typeof unreadCount !== 'number') { unreadCount = 0; } + var startingLoadedUnread = this.getLoadedUnreadCount(); return new Promise(function(resolve) { var upper; if (this.length === 0) { @@ -563,6 +564,10 @@ this.fetch(options).then(resolve); }.bind(this)).then(function() { var loadedUnread = this.getLoadedUnreadCount(); + if (startingLoadedUnread === loadedUnread) { + // that fetch didn't get us any more unread. stop fetching more. + return; + } if (loadedUnread < unreadCount) { return this.fetchConversation(conversationId, limit, unreadCount); }