[IMP] orm: fix vacuum of transient model
bzr revid: rco@openerp.com-20121221152914-qs1s9h1zwnyzft1m
This commit is contained in:
parent
2747e5bef2
commit
8ead65d82a
|
@ -5064,24 +5064,20 @@ class BaseModel(object):
|
||||||
|
|
||||||
def _transient_clean_rows_older_than(self, cr, seconds):
|
def _transient_clean_rows_older_than(self, cr, seconds):
|
||||||
assert self._transient, "Model %s is not transient, it cannot be vacuumed!" % self._name
|
assert self._transient, "Model %s is not transient, it cannot be vacuumed!" % self._name
|
||||||
'''Never delete rows used in last 5 minutes'''
|
# Never delete rows used in last 5 minutes
|
||||||
seconds = max(seconds, 300)
|
seconds = max(seconds, 300)
|
||||||
now_str = "(now() at time zone 'UTC')"
|
query = ("SELECT id FROM " + self._table + " WHERE"
|
||||||
cr.execute(
|
" COALESCE(write_date, create_date, (now() at time zone 'UTC'))::timestamp"
|
||||||
"SELECT id FROM " + self._table + " WHERE"
|
" < ((now() at time zone 'UTC') - interval %s)")
|
||||||
" COALESCE(write_date, create_date, " + now_str + ")::timestamp"
|
cr.execute(query, ("%s seconds" % seconds,))
|
||||||
"< (" + now_str + " - interval %s)", ("%s seconds" % seconds,))
|
|
||||||
ids = [x[0] for x in cr.fetchall()]
|
ids = [x[0] for x in cr.fetchall()]
|
||||||
if ids:
|
self.unlink(cr, SUPERUSER_ID, ids)
|
||||||
self.unlink(cr, SUPERUSER_ID, ids)
|
|
||||||
|
|
||||||
def _transient_clean_old_rows(self, cr, max_count):
|
def _transient_clean_old_rows(self, cr, max_count):
|
||||||
# Check how many rows we have in the table
|
# Check how many rows we have in the table
|
||||||
sql_statement = "SELECT count(*) as row_count FROM %s" % (self._table, )
|
cr.execute("SELECT count(*) AS row_count FROM " + self._table)
|
||||||
cr.execute(sql_statement)
|
|
||||||
res = cr.fetchall()
|
res = cr.fetchall()
|
||||||
row_count = res[0][0]
|
if res[0][0] <= max_count:
|
||||||
if row_count <= max_count:
|
|
||||||
return # max not reached, nothing to do
|
return # max not reached, nothing to do
|
||||||
self._transient_clean_rows_older_than(cr, 300)
|
self._transient_clean_rows_older_than(cr, 300)
|
||||||
|
|
||||||
|
@ -5103,10 +5099,9 @@ class BaseModel(object):
|
||||||
- the 10 rows that have been created/changed the last 5 minutes will NOT be deleted
|
- the 10 rows that have been created/changed the last 5 minutes will NOT be deleted
|
||||||
"""
|
"""
|
||||||
assert self._transient, "Model %s is not transient, it cannot be vacuumed!" % self._name
|
assert self._transient, "Model %s is not transient, it cannot be vacuumed!" % self._name
|
||||||
_transient_check_time = 20 # arbitrary limit on vacuum executions
|
_transient_check_time = 20 # arbitrary limit on vacuum executions
|
||||||
self._transient_check_count += 1
|
self._transient_check_count += 1
|
||||||
if ((not force)
|
if not force and (self._transient_check_count < _transient_check_time):
|
||||||
and (self._transient_check_count < _transient_check_time)):
|
|
||||||
return True # no vacuum cleaning this time
|
return True # no vacuum cleaning this time
|
||||||
self._transient_check_count = 0
|
self._transient_check_count = 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue