[FIX] stock: new cursor for orderpoint
On large databases, the orderpoint calculation can fail due to the huge cache used diring the process. Instead of using one cursor for the transaction, we create a new cursor every 100 orderpoints, to limit the cache size and speed up the performances. opw-726711 Closes #16158
This commit is contained in:
parent
794c9f5118
commit
a1aada9f76
|
@ -331,13 +331,12 @@ class procurement_order(osv.osv):
|
|||
'''
|
||||
Create procurement based on Orderpoint
|
||||
|
||||
:param bool use_new_cursor: if set, use a dedicated cursor and auto-commit after processing each procurement.
|
||||
:param bool use_new_cursor: if set, use dedicated cursors and auto-commit after processing
|
||||
100 orderpoints.
|
||||
This is appropriate for batch jobs only.
|
||||
'''
|
||||
if context is None:
|
||||
context = {}
|
||||
if use_new_cursor:
|
||||
cr = openerp.registry(cr.dbname).cursor()
|
||||
orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
|
||||
|
||||
procurement_obj = self.pool.get('procurement.order')
|
||||
|
@ -347,6 +346,8 @@ class procurement_order(osv.osv):
|
|||
while orderpoint_ids:
|
||||
ids = orderpoint_ids[:100]
|
||||
del orderpoint_ids[:100]
|
||||
if use_new_cursor:
|
||||
cr = openerp.registry(cr.dbname).cursor()
|
||||
for op in orderpoint_obj.browse(cr, uid, ids, context=context):
|
||||
try:
|
||||
prods = self._product_virtual_get(cr, uid, op)
|
||||
|
@ -381,12 +382,10 @@ class procurement_order(osv.osv):
|
|||
raise
|
||||
if use_new_cursor:
|
||||
cr.commit()
|
||||
cr.close()
|
||||
if prev_ids == ids:
|
||||
break
|
||||
else:
|
||||
prev_ids = ids
|
||||
|
||||
if use_new_cursor:
|
||||
cr.commit()
|
||||
cr.close()
|
||||
return {}
|
||||
|
|
Loading…
Reference in New Issue