summaryrefslogtreecommitdiff
path: root/openerp/modules/loading.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2015-01-21 11:29:05 +0100
committerRaphael Collet <rco@openerp.com>2015-01-21 11:29:05 +0100
commit592f1cd229a7ffd5ca9280cea6c035f0e36db59c (patch)
tree07f48f581647a1bdc49e8d1ea35cd34e6a82db9c /openerp/modules/loading.py
parent37e85a1e3520317e58f66daa8f58ecd833bd1208 (diff)
parent431f8de815bd87a20da867c88a13baf7104005e7 (diff)
Merge pull request #4676 from odoo-dev/8.0-speedup_loading-rco
[IMP] models: speedup registry loading (25% less time) The field setup on models is improved: only new-api fields are determined when building the model's class; the final _columns dict is derived from the fields once they are set up. This avoids setting up fields and columns at the same time, and finally overriding columns with the result of field setup. This branch also fixes the model setup in general: with the former code, a model could be introspected while it was only partially set up, and not all its fields were known. It incidentally fixes the "loss" of parameter partial that is necessary when loading custom fields. And during a partial setup, one2many custom fields are not introduced if their counterparts (model and many2one field) are not ready.
Diffstat (limited to 'openerp/modules/loading.py')
-rw-r--r--openerp/modules/loading.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/openerp/modules/loading.py b/openerp/modules/loading.py
index f80332d8dd5..9f22c2571a5 100644
--- a/openerp/modules/loading.py
+++ b/openerp/modules/loading.py
@@ -126,13 +126,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
migrations = openerp.modules.migration.MigrationManager(cr, graph)
_logger.info('loading %d modules...', len(graph))
- # Query manual fields for all models at once and save them on the registry
- # so the initialization code for each model does not have to do it
- # one model at a time.
- registry.fields_by_model = {}
- cr.execute('SELECT * FROM ir_model_fields WHERE state=%s', ('manual',))
- for field in cr.dictfetchall():
- registry.fields_by_model.setdefault(field['model'], []).append(field)
+ registry.clear_manual_fields()
# register, instantiate and initialize models for each modules
t0 = time.time()
@@ -162,13 +156,6 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
registry.setup_models(cr, partial=True)
init_module_models(cr, package.name, models)
- # Can't put this line out of the loop: ir.module.module will be
- # registered by init_module_models() above.
- modobj = registry['ir.module.module']
-
- if perform_checks:
- modobj.check(cr, SUPERUSER_ID, [module_id])
-
idref = {}
mode = 'update'
@@ -176,6 +163,13 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
mode = 'init'
if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
+ # Can't put this line out of the loop: ir.module.module will be
+ # registered by init_module_models() above.
+ modobj = registry['ir.module.module']
+
+ if perform_checks:
+ modobj.check(cr, SUPERUSER_ID, [module_id])
+
if package.state=='to upgrade':
# upgrading the module information
modobj.write(cr, SUPERUSER_ID, [module_id], modobj.get_values_from_terp(package.data))
@@ -227,9 +221,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
_logger.log(25, "%s modules loaded in %.2fs, %s queries", len(graph), time.time() - t0, openerp.sql_db.sql_counter - t0_sql)
- # The query won't be valid for models created later (i.e. custom model
- # created after the registry has been loaded), so empty its result.
- registry.fields_by_model = None
+ registry.clear_manual_fields()
cr.commit()