fix(contacts): Bound the size of the ranked contact cache

This commit is contained in:
Ben Gotow 2016-01-29 10:58:28 -08:00
parent 422d5f8d8f
commit e4727f0562

View file

@ -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