From 0ca4c838acb4c621571e9dcc47995f98d9c5f568 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 24 Feb 2022 13:36:10 +0000 Subject: [PATCH] [IMP] base: Batch calls to exists in _visible_menu_ids Purpose ======= Make 1 call per model (3-4 max) instead of 1 per menu. Part-of: odoo/odoo#85133 --- odoo/addons/base/models/ir_ui_menu.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_ui_menu.py b/odoo/addons/base/models/ir_ui_menu.py index d6c3e46c72e..d3495e8f7f7 100644 --- a/odoo/addons/base/models/ir_ui_menu.py +++ b/odoo/addons/base/models/ir_ui_menu.py @@ -88,7 +88,16 @@ class IrUiMenu(models.Model): lambda menu: not menu.groups_id or menu.groups_id & groups) # take apart menus that have an action - action_menus = menus.filtered(lambda m: m.action and m.action.exists()) + actions_by_model = defaultdict(set) + for action in menus.mapped('action'): + if action: + actions_by_model[action._name].add(action.id) + existing_actions = { + action + for model_name, action_ids in actions_by_model.items() + for action in self.env[model_name].browse(action_ids).exists() + } + action_menus = menus.filtered(lambda m: m.action and m.action in existing_actions) folder_menus = menus - action_menus visible = self.browse()