Question

There is this method:

 def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
        if args is None:
            args = []
        if context is None:
            context = {}
        ids = []
        if name:
            ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit)
        if not ids:
            ids = self.search(cr, uid, [('city_id', operator, name)] + args, limit=limit)
        if not ids:
            ids = self.search(cr, uid, [('street_id', operator, name)] + args, limit=limit)        
        return self.name_get(cr, uid, ids, context=context)

It finds what you want, but for some reason it searches very slowly when no search term is provided (note. It wouldn't be strange if it would return all records, but it still returns max 160 records).

There are few problems with this. First it has a limist search of 160 records for some reason even if you looked in method, it shows 100. And If I change to any number it still returns max records of 160 records. Looks like that parameter does not override default 160.

Now the other problem is that when I enter any phrase in search line, it finds results quite quickly, does not matter how many results it finds, because it limits to 160. That would be ok. But if I do not provide any phrase to search for and press little triangle (arrow) in openerp interface (look below for screenshot)

enter image description here

And the same thing happens when I delete search phrase in address completion field. It then also defaults to default search, which finds first 160 records ordered by zip (postal code) column order. For some reason this way it searches much slower. I only noticed this slow performance when I imported addresses (now there are more than 400k rows).

Does anyone know how could I improve this so called default search or at least limit return records so it might increase performance? (as I said for some reason changing limit= to some other number does not do anything).

Simple examples to understand problem:

1st example:

I write phrase City1 in address completion field. It finds first 160 records that has City1. Search is fast.

2nd example:

I don't write anyting in address completion field, but instead I press little arrow (the one in screenshot), to open detailed search. It finds first 160 records by postal code order. Search is slow.

3rd example:

I delete written phrase City1 (after I written it) from address completion field. It finds same records as in 2nd example. Search is slow.

P.S if anyone needs info about standard OpenERP parameters in ORM methods (like the one I provided): https://doc.openerp.com/6.0/developer/2_5_Objects_Fields_Methods/methods/

Was it helpful?

Solution

Removing order rows are returned (it was ordered by postal code), improved speed significantly. I guess if no one knows any better suggestion, this should be a good solution.

To be more specific in code there was this line:

_order = 'name' #name field is for postal code.

I deleted it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top