diff options
| author | ced <> | 2007-07-26 08:31:36 +0000 |
|---|---|---|
| committer | ced <> | 2007-07-26 08:31:36 +0000 |
| commit | cfbf7686547d7c9ac2c4165ea5b8d66af3c17b03 (patch) | |
| tree | e8dec50cc406474504c194e29e6a0282e149cbcd /bin/workflow | |
| parent | 1029e1323b2a303c707bfc3872abe67744cf310b (diff) | |
kernel: improve workflow
- add index on workitem, instance
- add cache on wkf
bzr revid: ced-81afcda4514578d17d998c4e3a8ff516d3346b97
Diffstat (limited to 'bin/workflow')
| -rw-r--r-- | bin/workflow/wkf_service.py | 15 | ||||
| -rw-r--r-- | bin/workflow/workitem.py | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/bin/workflow/wkf_service.py b/bin/workflow/wkf_service.py index 707ce97eb9c..5700896181d 100644 --- a/bin/workflow/wkf_service.py +++ b/bin/workflow/wkf_service.py @@ -42,6 +42,11 @@ class workflow_service(netsvc.Service): self.exportMethod(self.trg_validate) self.exportMethod(self.trg_redirect) self.exportMethod(self.trg_trigger) + self.exportMethod(self.clear_cache) + self.wkf_on_create_cache={} + + def clear_cache(self, cr, uid): + self.wkf_on_create_cache[cr.dbname]={} def trg_write(self, uid, res_type, res_id, cr): ident = (uid,res_type,res_id) @@ -63,8 +68,14 @@ class workflow_service(netsvc.Service): def trg_create(self, uid, res_type, res_id, cr): ident = (uid,res_type,res_id) - cr.execute('select id from wkf where osv=%s and on_create=True', (res_type,)) - for (wkf_id,) in cr.fetchall(): + self.wkf_on_create_cache.setdefault(cr.dbname, {}) + if res_type in self.wkf_on_create_cache[cr.dbname]: + wkf_ids = self.wkf_on_create_cache[cr.dbname][res_type] + else: + cr.execute('select id from wkf where osv=%s and on_create=True', (res_type,)) + wkf_ids = cr.fetchall() + self.wkf_on_create_cache[cr.dbname][res_type] = wkf_ids + for (wkf_id,) in wkf_ids: instance.create(cr, ident, wkf_id) def trg_validate(self, uid, res_type, res_id, signal, cr): diff --git a/bin/workflow/workitem.py b/bin/workflow/workitem.py index b01c9fbed3d..5fbf7ee7fe3 100644 --- a/bin/workflow/workitem.py +++ b/bin/workflow/workitem.py @@ -71,7 +71,9 @@ def process(cr, workitem, ident, signal=None, force_running=False): if trans['trigger_model']: ids = wkf_expr._eval_expr(cr,ident,workitem,trans['trigger_expr_id']) for id in ids: - cr.execute('insert into wkf_triggers (model,res_id,instance_id,workitem_id) values (%s,%d,%d,%d)', (trans['trigger_model'],id,workitem['inst_id'], workitem['id'])) + cr.execute('select nextval(\'wkf_workitem_id_seq\')') + id =cr.fetchone()[0] + cr.execute('insert into wkf_triggers (model,res_id,instance_id,workitem_id,id) values (%s,%d,%d,%d,%d)', (trans['trigger_model'],id,workitem['inst_id'], workitem['id'], id)) return True |
