diff options
| author | Raphael Collet <rco@odoo.com> | 2020-04-02 06:45:54 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-04-03 11:40:29 +0000 |
| commit | e0c2dde3244e1eed6c6fc2541281d0ec5ce86168 (patch) | |
| tree | 7d111095018267eb59ade6b8043c4977b420bbf2 /odoo/fields.py | |
| parent | 3ecb6fdcb0efcade41b9a6342718800b3293e4bf (diff) | |
[IMP] core: create/drop indexes all at once
Reduce the number of queries to create and drop indexes.
This saves 1.5% of the total installation time.
X-original-commit: 0e1e480da9d971575feba64038c4fa518ebe102b
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index 11ba2836853..ec384c09429 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -780,10 +780,10 @@ class Field(MetaField('DummyField', (object,), {})): column = columns.get(self.name) - # create/update the column, not null constraint, indexes + # create/update the column, not null constraint; the index will be + # managed by registry.check_indexes() self.update_db_column(model, column) self.update_db_notnull(model, column) - self.update_db_index(model, column) return not column @@ -831,22 +831,6 @@ class Field(MetaField('DummyField', (object,), {})): elif not self.required and has_notnull: sql.drop_not_null(model._cr, model._table, self.name) - def update_db_index(self, model, column): - """ Add or remove the index corresponding to ``self``. - - :param model: an instance of the field's model - :param column: the column's configuration (dict) if it exists, or ``None`` - """ - indexname = '%s_%s_index' % (model._table, self.name) - if self.index: - try: - with model._cr.savepoint(flush=False): - sql.create_index(model._cr, indexname, model._table, ['"%s"' % self.name]) - except psycopg2.OperationalError: - _schema.error("Unable to add index for %s", self) - else: - sql.drop_index(model._cr, indexname, model._table) - ############################################################################ # # Read from/write to database |
