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 40bfab40c0
commit 1ca2e930ef
3 changed files with 16 additions and 12 deletions

View file

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

View file

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

View file

@ -147,6 +147,7 @@ class AccountStore
@_cachedGetter "accountForId:#{id}", => _.findWhere(@_accounts, {id}) @_cachedGetter "accountForId:#{id}", => _.findWhere(@_accounts, {id})
aliases: => aliases: =>
@_cachedGetter "aliases", =>
aliases = [] aliases = []
for acc in @_accounts for acc in @_accounts
aliases.push(acc.me()) aliases.push(acc.me())