[FIX] core: improve get_files performances
On a standard odoo install, `MigrationManager._get_files` represent more than 4% of an install. This is because the legacy odoo/base/maintenance/migration path was added to upgrade.__path__ once by module, making the get_filed check 574^2 os.path.exists. This commit adds a check on initialize_sys_path to call it only once, and merge legacy path with upgrade-path management in order to benefit of the `up not in upgrade.__path__` check. This second part of the fix will also remove the local dir from the upgrades paths. A further improvement would be to fix MigrationManager in order to skip _get_file work on a fresh install, (wip by rco-odoo) closes odoo/odoo#45699 X-original-commit: 497330a695ed52a33f9c9b9c27b149446de0db29 Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
This commit is contained in:
@@ -32,6 +32,9 @@ 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)
|
||||
@@ -51,16 +54,12 @@ def initialize_sys_path():
|
||||
|
||||
# hook odoo.upgrade on upgrade-path
|
||||
from odoo import upgrade
|
||||
for up in tools.config['upgrade_path'].split(','):
|
||||
legacy_upgrade_path = os.path.join(base_path, 'base', 'maintenance', 'migrations')
|
||||
for up in (tools.config['upgrade_path'] or legacy_upgrade_path).split(','):
|
||||
up = os.path.normcase(os.path.abspath(tools.ustr(up.strip())))
|
||||
if up not in upgrade.__path__:
|
||||
upgrade.__path__.append(up)
|
||||
|
||||
# hook odoo.upgrade on legacy odoo/addons/base/maintenance/migrations symlink
|
||||
if not tools.config['upgrade_path']:
|
||||
upgrade.__path__.append(os.path.join(
|
||||
base_path, 'base', 'maintenance', 'migrations'))
|
||||
|
||||
# create decrecated module alias from odoo.addons.base.maintenance.migrations to odoo.upgrade
|
||||
spec = importlib.machinery.ModuleSpec("odoo.addons.base.maintenance", None, is_package=True)
|
||||
maintenance_pkg = importlib.util.module_from_spec(spec)
|
||||
|
||||
Reference in New Issue
Block a user