-
Notifications
You must be signed in to change notification settings - Fork 32.2k
[IMP] optimize loading and installation #48705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
162999e
[IMP] modules: don't mark all packages as 'update' unless necessary
rco-odoo 732b5cf
[IMP] core: perform `xmlid_lookup` in pure SQL
rco-odoo 5abb4e8
[IMP] core: avoid duplicates in `depends` and `depends_context`
rco-odoo cb4877d
[IMP] core: optimize `model._setup_base()`
rco-odoo 80d5f03
[IMP] core: remove `Field._slots`
rco-odoo 80a98b2
[IMP] core: optimize `field._setup_related_full`
rco-odoo 86a9f21
[IMP] core: compute field triggers lazily on registry
rco-odoo 18da9e6
[IMP] core: compute field_computed lazily
rco-odoo 656d91d
[IMP] core: optimize `model._auto_init()` on a new model
rco-odoo 3616533
[IMP] core: create/drop indexes all at once
rco-odoo 2c94dcb
[IMP] core: add/update foreign keys in batch
rco-odoo 9a6fd1f
[IMP] core: reflect models, fields and selections in batch
rco-odoo 773e1d1
[FIX] core: add NOT NULL constraints in post-init
rco-odoo b738009
[IMP] ir.ui.view: call _update_user_groups_view() once per install
rco-odoo be72417
[IMP] ir.ui.view: optimize `_compute_arch`
rco-odoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
| from odoo import models, fields, api, _ | ||
| from odoo.exceptions import UserError | ||
|
|
||
|
|
@@ -29,33 +31,45 @@ def write(self, vals): | |
|
|
||
| return super(IrModelFields, self).write(vals) | ||
|
|
||
| def _reflect_model(self, model): | ||
| super(IrModelFields, self)._reflect_model(model) | ||
| def _reflect_fields(self, model_names): | ||
| super()._reflect_fields(model_names) | ||
|
|
||
| # set 'serialization_field_id' on sparse fields; it is done here to | ||
| # ensure that the serialized field is reflected already | ||
| cr = self._cr | ||
| query = """ UPDATE ir_model_fields | ||
| SET serialization_field_id=%s | ||
| WHERE model=%s AND name=%s | ||
| RETURNING id | ||
| """ | ||
| fields_data = self._existing_field_data(model._name) | ||
|
|
||
| for field in model._fields.values(): | ||
| ser_field_id = None | ||
| ser_field_name = getattr(field, 'sparse', None) | ||
| if ser_field_name: | ||
| if ser_field_name not in fields_data: | ||
| msg = _("Serialization field `%s` not found for sparse field `%s`!") | ||
| raise UserError(msg % (ser_field_name, field.name)) | ||
| ser_field_id = fields_data[ser_field_name]['id'] | ||
|
|
||
| if fields_data[field.name]['serialization_field_id'] != ser_field_id: | ||
| cr.execute(query, (ser_field_id, model._name, field.name)) | ||
| record = self.browse(cr.fetchone()) | ||
| self.pool.post_init(record.modified, ['serialization_field_id']) | ||
| self.clear_caches() | ||
|
|
||
| # retrieve existing values | ||
| query = """ | ||
| SELECT model, name, id, serialization_field_id | ||
| FROM ir_model_fields | ||
| WHERE model IN %s | ||
| """ | ||
| cr.execute(query, [tuple(model_names)]) | ||
| existing = {row[:2]: row[2:] for row in cr.fetchall()} | ||
|
|
||
| # determine updates, grouped by value | ||
| updates = defaultdict(list) | ||
| for model_name in model_names: | ||
| for field_name, field in self.env[model_name]._fields.items(): | ||
| field_id, current_value = existing[(model_name, field_name)] | ||
| try: | ||
| value = existing[(model_name, field.sparse)][0] if field.sparse else None | ||
| except KeyError: | ||
| msg = _("Serialization field %r not found for sparse field %s!") | ||
| raise UserError(msg % (field.sparse, field)) | ||
| if current_value != value: | ||
| updates[value].append(field_id) | ||
|
|
||
| if not updates: | ||
| return | ||
|
|
||
| # update fields | ||
| query = "UPDATE ir_model_fields SET serialization_field_id=%s WHERE id IN %s" | ||
| for value, ids in updates.items(): | ||
| cr.execute(query, [value, tuple(ids)]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| records = self.browse(id_ for ids in updates.values() for id_ in ids) | ||
| self.pool.post_init(records.modified, ['serialization_field_id']) | ||
|
|
||
| def _instanciate_attrs(self, field_data): | ||
| attrs = super(IrModelFields, self)._instanciate_attrs(field_data) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.