Skip to content

Commit

Permalink
Improve performance on prestashop qty recompute
Browse files Browse the repository at this point in the history
The add/union operation between recordsets is slow, aggregate the ids in
a set and call the browse only once on the complete set is dramatically
faster. See guewen/connector-magento#9

(cherry picked from commit 5d617fd)
  • Loading branch information
guewen authored and sergio-teruel committed Sep 23, 2017
1 parent dc3324f commit 8f3e0bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions connector_prestashop/models/product_product/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ class PrestashopProductCombination(models.Model):
@api.multi
def recompute_prestashop_qty(self):
# group products by backend
backends = defaultdict(self.browse)
backends = defaultdict(set)
for product in self:
backends[product.backend_id] |= product
backends[product.backend_id].add(product.id)

for backend, products in backends.iteritems():
for backend, product_ids in backends.iteritems():
products = self.browse(product_ids)
products._recompute_prestashop_qty_backend(backend)
return True

Expand Down
7 changes: 4 additions & 3 deletions connector_prestashop/models/product_template/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ class PrestashopProductTemplate(models.Model):
@api.multi
def recompute_prestashop_qty(self):
# group products by backend
backends = defaultdict(self.browse)
backends = defaultdict(set)
for product in self:
backends[product.backend_id] |= product
backends[product.backend_id].add(product.id)

for backend, products in backends.iteritems():
for backend, product_ids in backends.iteritems():
products = self.browse(product_ids)
products._recompute_prestashop_qty_backend(backend)
return True

Expand Down

0 comments on commit 8f3e0bd

Please sign in to comment.