Fix the status table, vacuum on init every 24 hours
This commit is contained in:
parent
7261103c87
commit
765c999dfb
|
@ -18,14 +18,27 @@ class Inventory():
|
|||
)
|
||||
self._db.executescript("""
|
||||
BEGIN;
|
||||
CREATE TABLE IF NOT EXISTS status (vacuumtime integer);
|
||||
CREATE TABLE IF NOT EXISTS status
|
||||
(key text, value integer, UNIQUE(key) ON CONFLICT REPLACE);
|
||||
INSERT INTO status VALUES ('version', 1);
|
||||
CREATE TABLE IF NOT EXISTS objects
|
||||
(vector unique, expires integer, type integer, version integer,
|
||||
stream integer, tag, data, offset integer);
|
||||
COMMIT;
|
||||
""")
|
||||
self.rowid = len(self) or None
|
||||
# self._cur.execute('INSERT INTO status VALUES (?)', int(time.time()))
|
||||
cur = self._db.cursor()
|
||||
cur.execute("SELECT value FROM status WHERE key='lastvacuumtime'")
|
||||
now = int(time.time())
|
||||
try:
|
||||
vacuumed = cur.fetchone()[0]
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
if vacuumed < now - 86400: # 24 hours
|
||||
cur.execute('VACUUM')
|
||||
cur.execute("INSERT INTO status VALUES ('lastvacuumtime', ?)", (now,))
|
||||
self._db.commit()
|
||||
|
||||
def __objects(self, cur):
|
||||
return (
|
||||
|
|
Loading…
Reference in New Issue
Block a user