From 6042545c331b5ba003539a290bcffd0b11aa88dc Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 4 Sep 2019 14:27:02 +0000 Subject: [PATCH] [WIP] base: avoid useless view update on group write. Writting a view arch will trigger check_xml, which is quite expensive. Avoiding to write user_groups_view when arch didn't changed will slightly improve performance by avoiding to check already validated views. --- odoo/addons/base/models/res_users.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py index 1fde49a8d22..6fdf7bc8b56 100644 --- a/odoo/addons/base/models/res_users.py +++ b/odoo/addons/base/models/res_users.py @@ -1041,8 +1041,14 @@ class GroupsView(models.Model): return user def write(self, values): + # determine which values the "user groups view" depends on + VIEW_DEPS = ('category_id', 'implied_ids') + view_values0 = [g[name] for name in VIEW_DEPS if name in values for g in self] res = super(GroupsView, self).write(values) - self._update_user_groups_view() + # update the "user groups view" only if necessary + view_values1 = [g[name] for name in VIEW_DEPS if name in values for g in self] + if view_values0 != view_values1: + self._update_user_groups_view() # actions.get_bindings() depends on action records self.env['ir.actions.actions'].clear_caches() return res @@ -1062,7 +1068,6 @@ class GroupsView(models.Model): """ Modify the view with xmlid ``base.user_groups_view``, which inherits the user form view, and introduces the reified group fields. """ - # remove the language to avoid translations, it will be handled at the view level self = self.with_context(lang=None) @@ -1139,10 +1144,11 @@ class GroupsView(models.Model): xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, encoding="unicode") - new_context = dict(view._context) - new_context.pop('install_filename', None) # don't set arch_fs for this computed view - new_context['lang'] = None - view.with_context(new_context).write({'arch': xml_content}) + if xml_content != view.arch: # avoid useless xml validation if no change + new_context = dict(view._context) + new_context.pop('install_filename', None) # don't set arch_fs for this computed view + new_context['lang'] = None + view.with_context(new_context).write({'arch': xml_content}) def get_application_groups(self, domain): """ Return the non-share groups that satisfy ``domain``. """