Improve performance of getting products

Instead of calling odoo API 3 times, we're moving out the products
calling out of the loop of regions to improve the performance.

Change-Id: I9536d034ffe67caac2d4350f2e830528f5da5c34
This commit is contained in:
Feilong Wang 2017-06-28 13:56:03 +12:00
parent 00638fa410
commit dceb974059

View File

@ -86,20 +86,22 @@ class OdooDriver(driver.BaseDriver):
prices = {}
try:
# NOTE(flwang): Currently, the main bottle neck is the query of
# odoo, so we prefer to get all the products by one call and then
# filter them in Distil. And another problem is the filter for
# region doesn't work when query odoo.
c = self.category.search([('name', 'in', PRODUCT_CATEGORY)])
product_ids = self.product.search([('categ_id', 'in', c),
('sale_ok', '=', True),
('active', '=', True)])
products = self.product.read(product_ids)
for region in odoo_regions:
# Ensure returned region name is same with what user see from
# Keystone.
actual_region = self.reverse_region_mapping.get(region, region)
prices[actual_region] = collections.defaultdict(list)
# FIXME: Odoo doesn't suppport search by 'display_name'.
c = self.category.search([('name', 'in', PRODUCT_CATEGORY),
('display_name', 'ilike', region)])
product_ids = self.product.search([('categ_id', 'in', c),
('sale_ok', '=', True),
('active', '=', True)])
products = self.product.read(product_ids)
for product in products:
if region.upper() not in product['name_template']:
continue