Move VACUUM into cleanup()
This commit is contained in:
parent
bc5576039c
commit
af7b0ff778
|
@ -32,17 +32,16 @@ class Inventory():
|
|||
COMMIT;
|
||||
""")
|
||||
self.rowid = len(self) or None
|
||||
cur = self._db.cursor()
|
||||
cur.execute("SELECT value FROM status WHERE key='lastvacuumtime'")
|
||||
now = int(time.time())
|
||||
try:
|
||||
vacuumed = cur.fetchone()[0]
|
||||
self.lastvacuumtime = self._db.execute(
|
||||
"SELECT value FROM status WHERE key='lastvacuumtime'"
|
||||
).fetchone()[0]
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
if vacuumed < now - 86400: # 24 hours
|
||||
cur.execute('VACUUM')
|
||||
cur.execute("INSERT INTO status VALUES ('lastvacuumtime', ?)", (now,))
|
||||
self.lastvacuumtime = int(time.time())
|
||||
self._db.execute(
|
||||
"INSERT INTO status VALUES ('lastvacuumtime', ?)",
|
||||
(self.lastvacuumtime,)
|
||||
)
|
||||
self._db.commit()
|
||||
self._db.row_factory = self.__object
|
||||
|
||||
|
@ -61,24 +60,24 @@ class Inventory():
|
|||
'Not cleaning up, %s objects pending', len(self._pending))
|
||||
return
|
||||
with self._lock:
|
||||
now = int(time.time())
|
||||
cur = self._db.execute(
|
||||
'DELETE FROM objects WHERE expires < ?',
|
||||
(int(time.time()) - 3 * 3600,)
|
||||
)
|
||||
'DELETE FROM objects WHERE expires < ?', (now - 3 * 3600,))
|
||||
self._db.commit()
|
||||
self._deleted += cur.rowcount
|
||||
# conditional vacuum and validity check
|
||||
if self._deleted > 10000:
|
||||
logging.info('Doing VACUUM for objects')
|
||||
cur.execute('VACUUM')
|
||||
cur.execute(
|
||||
"INSERT INTO status VALUES ('lastvacuumtime', ?)",
|
||||
(int(time.time()),))
|
||||
self._db.commit()
|
||||
self._deleted = 0
|
||||
logging.info(
|
||||
'Deleted %s expired objects, %s pending',
|
||||
cur.rowcount, len(self._pending))
|
||||
# conditional vacuum and validity check
|
||||
# every 24 hours or after deleting a lot of items
|
||||
if self._deleted > 10000 or self.lastvacuumtime < now - 86400:
|
||||
logging.info('Doing VACUUM for objects')
|
||||
cur.execute('VACUUM')
|
||||
cur.execute(
|
||||
"INSERT INTO status VALUES ('lastvacuumtime', ?)", (now,))
|
||||
self._db.commit()
|
||||
self.lastvacuumtime = now
|
||||
self._deleted = 0
|
||||
|
||||
def filter(self, stream=None, object_type=None, tag=None):
|
||||
clauses = []
|
||||
|
|
Loading…
Reference in New Issue
Block a user