summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-04-02 06:45:54 +0000
committerRaphael Collet <rco@odoo.com>2020-04-03 11:40:28 +0000
commit3ecb6fdcb0efcade41b9a6342718800b3293e4bf (patch)
treeb0a8b291674dfc98629e024f0a1485b598b19d12 /odoo/tools
parent892e3df7010729da96278becbec29d7fe1f0985d (diff)
[IMP] core: optimize `model._auto_init()` on a new model
Create the table with all the columns from scratch, with the NOT NULL constraint when required. Also do not call `_check_removed_columns()` on a new table. This saves 0.5% of the total installation time. X-original-commit: 0727cacf5194a143b15ab4cb9893f3035a67be1f
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/sql.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py
index 3bcbd39e139..69968f78de8 100644
--- a/odoo/tools/sql.py
+++ b/odoo/tools/sql.py
@@ -48,11 +48,24 @@ def table_kind(cr, tablename):
cr.execute(query, (tablename,))
return cr.fetchone()[0] if cr.rowcount else None
-def create_model_table(cr, tablename, comment=None):
+def create_model_table(cr, tablename, comment=None, columns=()):
""" Create the table for a model. """
- cr.execute('CREATE TABLE "{}" (id SERIAL NOT NULL, PRIMARY KEY(id))'.format(tablename))
+ colspecs = ['id SERIAL NOT NULL'] + [
+ '"{}" {}'.format(columnname, columntype)
+ for columnname, columntype, columncomment in columns
+ ]
+ cr.execute('CREATE TABLE "{}" ({}, PRIMARY KEY(id))'.format(tablename, ", ".join(colspecs)))
+
+ queries, params = [], []
if comment:
- cr.execute('COMMENT ON TABLE "{}" IS %s'.format(tablename), (comment,))
+ queries.append('COMMENT ON TABLE "{}" IS %s'.format(tablename))
+ params.append(comment)
+ for columnname, columntype, columncomment in columns:
+ queries.append('COMMENT ON COLUMN "{}"."{}" IS %s'.format(tablename, columnname))
+ params.append(columncomment)
+ if queries:
+ cr.execute("; ".join(queries), params)
+
_schema.debug("Table %r: created", tablename)
def table_columns(cr, tablename):