This question has been flagged
1 Reply
5154 Views

I've got a problem in updating many resource in one, fast update.

I wrote simple module with workflow.

class wyn_wyn(osv.osv):
    """ Wyn """
    _name = 'wyn.wyn'
    _columns = {
                'title' : fields.char('Title', size=20, required=True),
                'savings' : fields.float('Planned savings', digits=(12,2)),
                'state': fields.selection([('draft', 'New'), ('accepted', 'Accepted'), ('refused', 'Refused')],
                        'Status', readonly=True, track_visibility='onchange')
                }

Then I wrote a wizard, where I want to calculate savings (let's say now set on 123):

def calculate(self, cr, uid, ids, context=None):
           wyn = self.pool.get("wyn.wyn");
           ids = wyn.search(cr, uid, '')
           wyn.write(cr, uid, ids, {'savings' : 123})
           return {'type': 'ir.actions.act_window_close'}

The problem is in write() method. It make one, nice, fast update on "savings" field, but then check every "wyn.wyn" resource about its workflow, one by one, what takes really long time. In the end of the write() method, is called step_workflow(), which works on every resource individually.

select * from wkf_workitem where inst_id=8056
select * from wkf_activity where id=5
select * from wkf_transition where act_from=5
select wkf_id from wkf_instance where id=8056
select state,flow_stop from wkf_workitem w left join wkf_activity a on (a.id=w.act_id) where w.inst_id=8056

How to solve this problem in efficient way? (disable workflow, code it in the other way, ...)

Avatar
Discard
Best Answer

Hi,

instead to use writeand search method in method calculate, use an sql request respectively INSERT and SELECT, this will be more quick.

Bye

Avatar
Discard
Author

That means that ORM should't be use in algorithms that populate more then few resources. I don't think that your solution is right. Look at write() method it takes ids to effectivly work on group of resources but workflow call make it useless

I had a function which passed to 20 minutes to 1 minute, but why try .... Bye