[FIX] base_action_rule: dumb patch to avoid repeated calls to related cron task

base.action.rule uses a trick to piggyback on the
first execution of ir.cron's poolJobs() to register
its ORM hooks. It was currently doing that every
single time poolJobs() was called, leading to
incessant querying the ORM objects for which a
base action rule exist. 
Now it will do it only once, and then respect the
scheduled executions.
Soon this mechanism will be removed and replaced
by a proper event handler for some 'ORM finished init'
event, to be fired by the server.

bzr revid: odo@openerp.com-20110624102419-safqqq1hcc5v1tau
This commit is contained in:
Olivier Dony 2011-06-24 12:24:19 +02:00
parent 2e7721f1af
commit 48e5f7b773
1 changed files with 17 additions and 14 deletions

View File

@ -487,21 +487,24 @@ base_action_rule()
class ir_cron(osv.osv):
_inherit = 'ir.cron'
_inherit = 'ir.cron'
_init_done = False
def _poolJobs(self, db_name, check=False):
try:
db = pooler.get_db(db_name)
except:
return False
cr = db.cursor()
try:
next = datetime.now().strftime('%Y-%m-%d %H:00:00')
# Putting nextcall always less than current time in order to call it every time
cr.execute('UPDATE ir_cron set nextcall = \'%s\' where numbercall<>0 and active and model=\'base.action.rule\' ' % (next))
finally:
cr.commit()
cr.close()
if not self._init_done:
self._init_done = True
try:
db = pooler.get_db(db_name)
except:
return False
cr = db.cursor()
try:
next = datetime.now().strftime('%Y-%m-%d %H:00:00')
# Putting nextcall always less than current time in order to call it every time
cr.execute('UPDATE ir_cron set nextcall = \'%s\' where numbercall<>0 and active and model=\'base.action.rule\' ' % (next))
finally:
cr.commit()
cr.close()
super(ir_cron, self)._poolJobs(db_name, check=check)