Skip to content

Commit

Permalink
[FIX] odoo: stop bloating sys.meta_path
Browse files Browse the repository at this point in the history
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#45780
- odoo#45662

closes odoo#53098

Signed-off-by: Olivier Dony (odo) <[email protected]>
  • Loading branch information
madprog authored and odony committed Jun 16, 2020
1 parent 972eab4 commit 175928c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions odoo/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ def initialize_sys_path():
``import odoo.addons.crm``) works even if the addons are not in the
PYTHONPATH.
"""
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__:
Expand Down Expand Up @@ -143,9 +141,10 @@ def initialize_sys_path():
sys.modules["odoo.addons.base.maintenance"] = maintenance_pkg
sys.modules["odoo.addons.base.maintenance.migrations"] = upgrade

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):
Expand Down

0 comments on commit 175928c

Please sign in to comment.