Browse Source

[IMP] Cache account in keychain backend

This commit creates a computed field on the keychain backend, so
that repeated calls to _get_keychain_account() will return the
value from the ORM cache rather than repeating the query each time.
pull/1168/head
andreparames 7 years ago
parent
commit
ffd674ff79
  1. 15
      keychain/models/keychain_backend.py

15
keychain/models/keychain_backend.py

@ -19,6 +19,13 @@ class KeychainBackend(models.AbstractModel):
compute="_compute_keychain",
inverse="_inverse_keychain",
help="Additionnal data as json")
keychain_account_id = fields.Many2one(
'keychain.account', compute='_compute_keychain_account')
@api.multi
def _compute_keychain_account(self):
for backend in self:
backend.keychain_account_id = backend._get_existing_keychain()
@api.multi
def _get_technical_name(self):
@ -47,11 +54,11 @@ class KeychainBackend(models.AbstractModel):
@api.multi
def _get_keychain_account(self):
self.ensure_one()
account = self._get_existing_keychain()
if not account:
if not self.keychain_account_id:
vals = self._prepare_keychain()
account = self.env['keychain.account'].create(vals)
return account
self.keychain_account_id = self.env['keychain.account'].create(
vals)
return self.keychain_account_id
@api.multi
def _inverse_password(self):

Loading…
Cancel
Save