From e4727f05626384974349590093778c78d901494a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Fri, 29 Jan 2016 10:58:28 -0800 Subject: [PATCH] fix(contacts): Bound the size of the ranked contact cache --- src/flux/stores/contact-store.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flux/stores/contact-store.coffee b/src/flux/stores/contact-store.coffee index fcd4fab9a..e19133b1c 100644 --- a/src/flux/stores/contact-store.coffee +++ b/src/flux/stores/contact-store.coffee @@ -151,6 +151,12 @@ class ContactStore extends NylasStore @_rankedContacts = [] return + # Sort the emails by rank and then clip to 400 so that our ranked cache + # has a bounded size. + emails = _.sortBy emails, (email) -> + (- (rankings[email.toLowerCase()] ? 0) / 1) + emails.length = 400 if emails.length > 400 + DatabaseStore.findAll(Contact, {email: emails}).then (contacts) => contacts = @_distinctByEmail(contacts) for contact in contacts