[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 <rco@odoo.com>
This commit is contained in:
nda-odoo
2022-04-22 12:04:27 +02:00
parent d7716f071d
commit c7d54d9ef1
+4 -2
View File
@@ -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')