diff options
| author | RomainLibert <rli@odoo.com> | 2019-01-11 11:44:49 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-02-05 11:44:21 +0000 |
| commit | 6dbdfb9bf73b7838b43e7804f51c4e64d1039359 (patch) | |
| tree | be10a9d92bc227f5004cd16c4c69adc749f2ae06 /addons/analytic/models | |
| parent | 0b79687155c9ec759f6ce3a4c736847e3db5c3ac (diff) | |
[IMP] various: optimize _name_search
In the overrides of _name_search we should avoid creating domains with
huge lists of ids as it is inefficient.
We can also make sure that we optimize the empty search as in this case
the custom domain doesn't make sense, we can simply search on an empty
domain and, thanks to the limit argument, still keep a fast query.
Linked to task 1918906
Thanks to @odony and @nseinlet
closes odoo/odoo#30155
Diffstat (limited to 'addons/analytic/models')
| -rw-r--r-- | addons/analytic/models/analytic_account.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index 3d9b9b64279..187d53d1ad7 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -157,11 +157,11 @@ class AccountAnalyticAccount(models.Model): if operator not in ('ilike', 'like', '=', '=like', '=ilike'): return super(AccountAnalyticAccount, self)._name_search(name, args, operator, limit, name_get_uid=name_get_uid) args = args or [] - domain = ['|', ('code', operator, name), ('name', operator, name)] - partners_ids = self.env['res.partner']._search([('name', operator, name)], access_rights_uid=name_get_uid) - if partners_ids: - domain = ['|'] + domain + [('partner_id', 'in', partners_ids)] - analytic_account_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid) + if operator == 'ilike' and not (name or '').strip(): + domain = [] + else: + domain = ['|', '|', ('code', operator, name), ('name', operator, name), ('partner_id.name', operator, name)] + analytic_account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return self.browse(analytic_account_ids).name_get() |
