From 0cb3ed4e8ff7c53efa021c09e0aba91ebfa30a56 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 23 Feb 2016 14:42:58 +0100 Subject: [PATCH] [FIX] product: add index on pricelist items for better perf With a high number of pricelist items (8.000.000 in the observed case), the SQL request performed in `_price_rule_get_multi` took a significant time (>3000ms) to be executed without an index on the `pricelist_id`. opw-670153 --- addons/product/pricelist.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index b23691384e9..d2d8e542e5f 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -269,6 +269,11 @@ class product_pricelist_item(osv.osv): _description = "Pricelist item" _order = "applied_on, min_quantity desc" + def init(self, cr): + cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('product_pricelist_item_pricelist_id_index',)) + if not cr.fetchone(): + cr.execute('CREATE INDEX product_pricelist_item_pricelist_id_index ON product_pricelist_item (pricelist_id)') + def _check_recursion(self, cr, uid, ids, context=None): for obj_list in self.browse(cr, uid, ids, context=context): if obj_list.base == 'pricelist':