Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
3318 Zobrazení

Example:

I have a model with a many2one to 'res.partner'. I have a lot of records in that model, dozens of thousands of records, and a few thousands in res.partner. I also have the necessary indexes.

Why is this:

search([('customer_id.name', 'like', 'somename')])

way faster than this:

search([('customer_id', 'like', 'somename')])

?

Avatar
Zrušit
Autor

Hi, thanks. I forgot to mention that I was using Odoo 8, but anyway the code is basically the same for that method.

I am not quite sure about why the double search is made. And I don't understand why the method is named "_search" and not "search".

But you gave me good hint.

Thank you.

The double search is to find the 10 people who work for Azure when you search for "Azure".

Nejlepší odpověď

Good Question!

The default search for res.partner adds the searching of parent_id:

https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/models/res_partner.py#L739

Your first search will look for Azure Interior in the name.

Your second search will look for Azure Interior in both the name AND the parent_id name.


Your second search is doing TWO searches at once!


Avatar
Zrušit
Autor Nejlepší odpověď

Yes, I see. The difference is in the active_test parameter.

But the delay is not doubled, it is much more. About 1 min with one method and 1 second with the other one.

Anyway, I found a way to fix this, I redifined search method on my model to replace searches with customer_id with customer_id.name.

Thanks.

Avatar
Zrušit
Autor

Actually, I don't think method _name_search has something to do. I commented that method out and the delay is still there.

My previous solution cause some other problems.

So, I had to implement a new one.

1- Create a function field that returns the same value as customer_id. Let's say customer_id2

2- Add a search function for that field, fnct_search=_search_by_customer. This function will search by customer_id.name

3- Remove customer_id from Advanced Search.

Related Posts Odpovědi Zobrazení Aktivita
1
čvc 25
562
1
úno 25
1262
0
zář 23
2224
2
čvn 23
4047
1
srp 22
12788