From ee8756b31186f2f21e9b70e124f29c678cebaea7 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 15 Feb 2021 14:57:48 +0000 Subject: [PATCH] [IMP] base: bypass _inverse_arch() in view creation By default, whatever is written on field 'arch' is handled by its inverse method inverse_arch(), which writes on the low-level field 'arch_db'. When writing on 'arch_db', the cache is cleared, which leads to performance loss because the arch needs to be re-fetched. This optimization bypasses the inverse method on view creation, this is safe as there is nothing wrong in the cache and makes view creation 20% faster, and installation 7% faster. --- odoo/addons/base/models/ir_ui_view.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index b2f6ef7a0ba..7bdedb5a7e2 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -504,6 +504,16 @@ actual arch. values['name'] = "%s %s" % (values.get('model'), values['type']) # Create might be called with either `arch` (xml files), `arch_base` (form view) or `arch_db`. values['arch_prev'] = values.get('arch_base') or values.get('arch_db') or values.get('arch') + # write on arch: bypass _inverse_arch() + if 'arch' in values: + values['arch_db'] = values.pop('arch') + if 'install_filename' in self._context: + # we store the relative path to the resource instead of the absolute path, if found + # (it will be missing e.g. when importing data-only modules using base_import_module) + path_info = get_resource_from_path(self._context['install_filename']) + if path_info: + values['arch_fs'] = '/'.join(path_info[0:2]) + values['arch_updated'] = False values.update(self._compute_defaults(values)) self.clear_caches()