Add vacuum after deleting 10000 objects
This commit is contained in:
parent
6e591da4d6
commit
0d0181cf0b
|
@ -1,5 +1,6 @@
|
||||||
"""Inventory implementation using sqlite"""
|
"""Inventory implementation using sqlite"""
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import threading
|
import threading
|
||||||
|
@ -14,6 +15,7 @@ class Inventory():
|
||||||
"""sqlite inventory"""
|
"""sqlite inventory"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
|
self._deleted = 0
|
||||||
self._db = sqlite3.connect(
|
self._db = sqlite3.connect(
|
||||||
os.path.join(shared.data_directory, 'objects.dat'),
|
os.path.join(shared.data_directory, 'objects.dat'),
|
||||||
check_same_thread=False
|
check_same_thread=False
|
||||||
|
@ -54,12 +56,22 @@ class Inventory():
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self._db.execute(
|
cur = self._db.execute(
|
||||||
'DELETE FROM objects WHERE expires < ?',
|
'DELETE FROM objects WHERE expires < ?',
|
||||||
(int(time.time()) - 3 * 3600,)
|
(int(time.time()) - 3 * 3600,)
|
||||||
)
|
)
|
||||||
self._db.commit()
|
self._db.commit()
|
||||||
|
self._deleted += cur.rowcount
|
||||||
# conditional vacuum and validity check
|
# 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', cur.rowcount)
|
||||||
|
|
||||||
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