From c7d54d9ef14cb7def58072f563b4b9d89286d07c Mon Sep 17 00:00:00 2001 From: nda-odoo Date: Thu, 14 Apr 2022 21:18:04 +0000 Subject: [PATCH] [FIX] base: performance of has_group() Avoid calling with_user() inside method has_group() when possible, as it represents a major overhead inside this method which is commonly called. This sole optimization speeds up the accounting general ledger by about 6%. closes odoo/odoo#89206 X-original-commit: e858507aaf01c3701bf5642978490d7947acf35d Signed-off-by: Raphael Collet --- odoo/addons/base/models/res_users.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py index b9f675e90ce..8210e58396b 100644 --- a/odoo/addons/base/models/res_users.py +++ b/odoo/addons/base/models/res_users.py @@ -828,8 +828,10 @@ class Users(models.Model): def has_group(self, group_ext_id): # use singleton's id if called on a non-empty recordset, otherwise # context uid - uid = self.id or self._uid - return self.with_user(uid)._has_group(group_ext_id) + uid = self.id + if uid and uid != self._uid: + self = self.with_user(uid) + return self._has_group(group_ext_id) @api.model @tools.ormcache('self._uid', 'group_ext_id')