diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2016-09-30 11:43:30 +0200 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2016-09-30 12:58:45 +0200 |
| commit | c8ca71fc62b44dbb6ba9eebf9091dae87c723cf4 (patch) | |
| tree | b9dbdd3d0791febc2e3f508c3e4340462463c354 /addons | |
| parent | 00aab045b0e0b769cea6e0a152a30a33de64e2ca (diff) | |
[IMP] stock_account: stock_history slow read_group
On a given instance with 600 000 stock.history, the query changed by
this commit takes:
- before this change => 32 minutes
- after this change => 20 seconds
opw-685747
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/stock_account/wizard/stock_valuation_history.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/addons/stock_account/wizard/stock_valuation_history.py b/addons/stock_account/wizard/stock_valuation_history.py index a7c31e2381a..65169c6dc13 100644 --- a/addons/stock_account/wizard/stock_valuation_history.py +++ b/addons/stock_account/wizard/stock_valuation_history.py @@ -56,11 +56,11 @@ class stock_history(osv.osv): for ids in group_lines.values(): for product_id in ids: line_ids.add(product_id) - line_ids = list(line_ids) lines_rec = {} if line_ids: - cr.execute('SELECT id, product_id, price_unit_on_quant, company_id, quantity FROM stock_history WHERE id in %s', (tuple(line_ids),)) - lines_rec = cr.dictfetchall() + move_ids = tuple(abs(line_id) for line_id in line_ids) + cr.execute('SELECT id, product_id, price_unit_on_quant, company_id, quantity FROM stock_history WHERE move_id in %s', (move_ids,)) + lines_rec = tuple(rec for rec in cr.dictfetchall() if rec['id'] in line_ids) lines_dict = dict((line['id'], line) for line in lines_rec) product_ids = list(set(line_rec['product_id'] for line_rec in lines_rec)) products_rec = self.pool['product.product'].read(cr, uid, product_ids, ['cost_method', 'id'], context=context) |
