[IMP] core: avoid to check access rules on empty recordset

Checking access rules only makes sence if we have some records,
_filter_access_rules will always return a subset or current
recordset, and a subset or a empty recordset is an empty recordset.

closes odoo/odoo#32313

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Xavier-Do
2019-04-02 15:39:30 +00:00
parent edef08eeee
commit b5c2004160
2 changed files with 9 additions and 0 deletions
@@ -76,3 +76,9 @@ class TestRules(TransactionCase):
container_user.write({'some_ids': [(5,)]})
self.assertItemsEqual(container_user.some_ids.ids, [])
self.assertItemsEqual(container_admin.some_ids.ids, [self.id2])
def test_access_rule_performance(self):
env = self.env(user=self.browse_ref('base.public_user'))
Model = env['test_access_right.some_obj']
with self.assertQueryCount(0):
Model._filter_access_rules('read')
+3
View File
@@ -3102,6 +3102,9 @@ Fields:
if self._uid == SUPERUSER_ID:
return self
if not self._ids:
return self
if self.is_transient():
# Only one single implicit access rule for transient models: owner only!
# This is ok to hardcode because we assert that TransientModels always