From ffd674ff79b6fcec7ec355d12dab5695c3af0181 Mon Sep 17 00:00:00 2001 From: andreparames Date: Thu, 22 Feb 2018 09:48:06 +0100 Subject: [PATCH] [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. --- keychain/models/keychain_backend.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/keychain/models/keychain_backend.py b/keychain/models/keychain_backend.py index c266771b9..62a3f1e6c 100644 --- a/keychain/models/keychain_backend.py +++ b/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):