diff options
| author | Raphael Collet <rco@odoo.com> | 2020-06-17 12:18:29 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-08-18 13:02:41 +0000 |
| commit | 6f87bbbfc8e34b412fe9c129c002269540fa5a30 (patch) | |
| tree | 653c89e5c577be2b7e6e4278172bf7dd77e9b17b | |
| parent | 1f48130d2bd055835ee428a21922331d126285a3 (diff) | |
[IMP] core: use _search() and _name_search() for sub-searches
This avoids the formatting part of those methods (`browse` in the case
of `search`, `display_name` in the case of `name_search`), which is
useless in most cases.
This also enables further optimizations where `_search` and
`_name_search` return subqueries instead of record ids.
| -rw-r--r-- | odoo/osv/expression.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index 3b5d509df61..90dd394537c 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -565,7 +565,7 @@ class expression(object): return list({ rid for name in names - for rid, rname in comodel.name_search(name, [], 'ilike', limit=None) + for rid in comodel._name_search(name, [], 'ilike', limit=None) }) return list(value) @@ -581,13 +581,13 @@ class expression(object): for rec in left_model.browse(ids) ]) if prefix: - return [(left, 'in', left_model.search(doms, order='id').ids)] + return [(left, 'in', left_model._search(doms, order='id'))] return doms else: parent_name = parent or left_model._parent_name child_ids = set(ids) while ids: - ids = left_model.search([(parent_name, 'in', ids)], order='id').ids + ids = left_model._search([(parent_name, 'in', ids)], order='id') child_ids.update(ids) return [(left, 'in', list(child_ids))] @@ -739,12 +739,12 @@ class expression(object): raise NotImplementedError('auto_join attribute not supported on field %s' % field) elif len(path) > 1 and field.store and field.type == 'many2one': - right_ids = comodel.with_context(active_test=False).search([('.'.join(path[1:]), operator, right)], order='id').ids + right_ids = comodel.with_context(active_test=False)._search([(path[1], operator, right)], order='id') push((path[0], 'in', right_ids), model, alias) # Making search easier when there is a left operand as one2many or many2many elif len(path) > 1 and field.store and field.type in ('many2many', 'one2many'): - right_ids = comodel.with_context(**field.context).search([('.'.join(path[1:]), operator, right)], order='id').ids + right_ids = comodel.with_context(**field.context)._search([(path[1], operator, right)], order='id') push((path[0], 'in', right_ids), model, alias) elif not field.store: @@ -759,7 +759,7 @@ class expression(object): else: # Let the field generate a domain. if len(path) > 1: - right = comodel.search([('.'.join(path[1:]), operator, right)], order='id').ids + right = comodel._search([(path[1], operator, right)], order='id') operator = 'in' domain = field.determine_domain(model, operator, right) @@ -790,13 +790,13 @@ class expression(object): if isinstance(right, str): op2 = (TERM_OPERATORS_NEGATION[operator] if operator in NEGATIVE_TERM_OPERATORS else operator) - ids2 = [x[0] for x in comodel.name_search(right, domain or [], op2, limit=None)] + ids2 = comodel._name_search(right, domain or [], op2, limit=None) elif isinstance(right, collections.abc.Iterable): ids2 = right else: ids2 = [right] if ids2 and inverse_is_int and domain: - ids2 = comodel.search([('id', 'in', ids2)] + domain, order='id').ids + ids2 = comodel._search([('id', 'in', ids2)] + domain, order='id') if ids2 and comodel._fields[field.inverse_name].store: op1 = 'not inselect' if operator in NEGATIVE_TERM_OPERATORS else 'inselect' @@ -835,7 +835,7 @@ class expression(object): # determine ids2 in comodel ids2 = to_ids(right, comodel, leaf) domain = HIERARCHY_FUNCS[operator]('id', ids2, comodel) - ids2 = comodel.search(domain, order='id').ids + ids2 = comodel._search(domain, order='id') # rewrite condition in terms of ids2 if comodel == model: @@ -850,7 +850,7 @@ class expression(object): domain = field.get_domain_list(model) op2 = (TERM_OPERATORS_NEGATION[operator] if operator in NEGATIVE_TERM_OPERATORS else operator) - ids2 = [x[0] for x in comodel.name_search(right, domain or [], op2, limit=None)] + ids2 = comodel._name_search(right, domain or [], op2, limit=None) elif isinstance(right, collections.abc.Iterable): ids2 = right else: @@ -889,7 +889,7 @@ class expression(object): operator = dict_op[operator] elif isinstance(right, list) and operator in ['!=', '=']: # for domain (FIELD,'=',['value1','value2']) operator = dict_op[operator] - res_ids = [x[0] for x in comodel.with_context(active_test=False).name_search(right, [], operator, limit=None)] + res_ids = comodel.with_context(active_test=False)._name_search(right, [], operator, limit=None) if operator in NEGATIVE_TERM_OPERATORS: res_ids.append(False) # TODO this should not be appended if False was in 'right' return left, 'in', res_ids |
