[IMP] mrp: performance improvment: avoid select sql inside loops
bzr revid: olt@tinyerp.com-20100920101025-30zwlatr9qs2akso
This commit is contained in:
parent
c5ef622acb
commit
b9d743fc68
|
@ -19,6 +19,8 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import itertools
|
||||
import operator
|
||||
from datetime import datetime
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
@ -356,8 +358,7 @@ class many2many_domain(fields.many2many):
|
|||
res = {}
|
||||
move_obj = obj.pool.get('stock.move')
|
||||
for prod in obj.browse(cr, user, ids, context=context):
|
||||
cr.execute("SELECT move_id from mrp_production_move_ids where\
|
||||
production_id=%s" % (prod.id))
|
||||
cr.execute("SELECT move_id from mrp_production_move_ids where production_id=%s" % (prod.id))
|
||||
m_ids = map(lambda x: x[0], cr.fetchall())
|
||||
final = move_obj.search(cr, user, self._domain + [('id', 'in', tuple(m_ids))])
|
||||
res[prod.id] = final
|
||||
|
@ -371,13 +372,15 @@ class one2many_domain(fields.one2many):
|
|||
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
|
||||
if not context:
|
||||
context = {}
|
||||
res = {}
|
||||
|
||||
move_obj = obj.pool.get('stock.move')
|
||||
for prod in obj.browse(cr, user, ids, context=context):
|
||||
cr.execute("SELECT id from stock_move where production_id=%s" % (prod.id))
|
||||
m_ids = map(lambda x: x[0], cr.fetchall())
|
||||
final = move_obj.search(cr, user, self._domain + [('id', 'in', tuple(m_ids))])
|
||||
res[prod.id] = final
|
||||
res = {}.fromkeys(ids, [])
|
||||
key = operator.itemgetter(0)
|
||||
move_ids = move_obj.search(cr, user, self._domain+[('production_id', 'in', tuple(ids))], context=context)
|
||||
related_move_map = [(o.production_id.id, o.id) for o in move_obj.browse(cr, user, move_ids, context=context)]
|
||||
related_move_dict = dict((k, [v[1] for v in itr]) for k, itr in itertools.groupby(related_move_map, key))
|
||||
res.update(related_move_dict)
|
||||
|
||||
return res
|
||||
|
||||
class mrp_production(osv.osv):
|
||||
|
|
Loading…
Reference in New Issue