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