[FIX] base: testing overhead of related field creation

The real overhead of creating a related field is actually two queries:
- one query in update_db_related, the purpose of this test
- one more query for _compute_related_field_id in flush()

With the previous version of this test, one prefetching done in the
first create was not present in the second create since it was in cache.

The fix clears the caches to make the creation of both fields in the
same situation, such that query counts are compared in a fair way.

Part-of: odoo/odoo#78514
This commit is contained in:
Xavier-Do
2021-10-22 17:34:18 +00:00
parent b4b260b916
commit e966beb3ca
+17 -13
View File
@@ -501,20 +501,24 @@ class TestCustomFields(common.TransactionCase):
])
partners.flush()
# determine how many queries it takes to create a non-computed field
query_count = self.cr.sql_log_count
self.env['ir.model.fields'].create({
'model_id': self.env['ir.model']._get_id('res.partner'),
'name': 'x_oh_box',
'field_description': 'x_oh_box',
'ttype': 'char',
})
query_count = self.cr.sql_log_count - query_count
# create the related field, and assert it only takes 1 extra query
with self.assertQueryCount(query_count + 1):
# create a non-computed field, and assert how many queries it takes
model_id = self.env['ir.model']._get_id('res.partner')
query_count = 42
with self.assertQueryCount(query_count):
self.env.registry.clear_caches()
self.env['ir.model.fields'].create({
'model_id': self.env['ir.model']._get_id('res.partner'),
'model_id': model_id,
'name': 'x_oh_box',
'field_description': 'x_oh_box',
'ttype': 'char',
'store': True,
})
# same with a related field, it only takes 2 extra queries
with self.assertQueryCount(query_count + 2):
self.env.registry.clear_caches()
self.env['ir.model.fields'].create({
'model_id': model_id,
'name': 'x_oh_boy',
'field_description': 'x_oh_boy',
'ttype': 'char',