İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
3330 Görünümler

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
Vazgeç
Üretici

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".

En İyi Yanıt

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
Vazgeç
Üretici En İyi Yanıt

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
Vazgeç
Üretici

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.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Tem 25
564
Search a message Çözüldü
1
Şub 25
1265
0
Eyl 23
2230
2
Haz 23
4049
1
Ağu 22
12791