[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 <chs@odoo.com>
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
This commit is contained in:
Paul Morelle
2020-06-17 08:49:29 +00:00
parent f5089a0b0e
commit 8a94f62e08
+2 -5
View File
@@ -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):