perf(threads): Cache aliases to avoid GC thrashing in isMeAccount

This commit is contained in:
Ben Gotow 2016-02-04 20:13:37 -08:00
parent 1b932eb3e5
commit 80b70b6e54
3 changed files with 16 additions and 12 deletions

View file

@ -133,9 +133,13 @@ describe "Contact", ->
expect(c1.isMe()).toBe(true)
it "also matches any aliases you've created", ->
spyOn(AccountStore, 'aliases').andReturn [
new Contact(name: 'Ben Other', email: 'ben22@nylas.com', accountId: TEST_ACCOUNT_ID)
]
spyOn(AccountStore, 'accounts').andReturn [
new Account
provider: "gmail"
accountId: TEST_ACCOUNT_ID
aliases: ["Ben Other <ben22@nylas.com>"]
emailAddress: 'ben@nylas.com'
]

View file

@ -101,10 +101,9 @@ class Contact extends Model
for account in AccountStore.accounts()
if Utils.emailIsEquivalent(@email, account.emailAddress)
return account
for alias in account.aliases
if Utils.emailIsEquivalent(@email, Contact.fromString(alias).email)
return account
for alias in AccountStore.aliases()
if Utils.emailIsEquivalent(@email, alias.email)
return AccountStore.accountForId(alias.accountId)
return null

View file

@ -147,14 +147,15 @@ class AccountStore
@_cachedGetter "accountForId:#{id}", => _.findWhere(@_accounts, {id})
aliases: =>
aliases = []
for acc in @_accounts
aliases.push(acc.me())
for alias in acc.aliases
aliasContact = acc.meUsingAlias(alias)
aliasContact.isAlias = true
aliases.push(aliasContact)
return aliases
@_cachedGetter "aliases", =>
aliases = []
for acc in @_accounts
aliases.push(acc.me())
for alias in acc.aliases
aliasContact = acc.meUsingAlias(alias)
aliasContact.isAlias = true
aliases.push(aliasContact)
return aliases
aliasesFor: (accountsOrIds) =>
ids = accountsOrIds.map (accOrId) ->