From 8a94f62e08f40af5dd67bcc59cab90d6b339012d Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Tue, 16 Jun 2020 20:49:37 +0000 Subject: [PATCH] [FIX] odoo: stop bloating sys.meta_path Every call of initialize_sys_path was adding two new hooks to the sys.meta_path, resulting in very long loading times on databases having a lot of modules. For example, 2.27s instead of 752 on a database having 130 installed modules. References: - odoo/odoo#45780 - odoo/odoo#45662 closes odoo/odoo#53121 X-original-commit: 2444fde7f852787d87589a93c4bc385d76ff20e9 Signed-off-by: Christophe Simonis Signed-off-by: Olivier Dony (odo) --- odoo/modules/module.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/odoo/modules/module.py b/odoo/modules/module.py index f545a720109..61117965b0f 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -102,10 +102,6 @@ def initialize_sys_path(): Setup the addons path ``odoo.addons.__path__`` with various defaults and explicit directories. """ - # if getattr(initialize_sys_path, 'called', False): # only initialize once - # return - initialize_sys_path.called = True - # hook odoo.addons on data dir dd = os.path.normcase(tools.config.addons_data_dir) if os.access(dd, os.R_OK) and dd not in odoo.addons.__path__: @@ -138,9 +134,10 @@ def initialize_sys_path(): sys.modules["odoo.addons.base.maintenance.migrations"] = upgrade # hook deprecated module alias from openerp to odoo and "crm"-like to odoo.addons - if getattr(initialize_sys_path, 'called', False): # only initialize once + if not getattr(initialize_sys_path, 'called', False): # only initialize once sys.meta_path.insert(0, OdooHook()) sys.meta_path.insert(0, AddonsHook()) + initialize_sys_path.called = True def get_module_path(module, downloaded=False, display_warning=True):