Execute vacuum command after cleaning up DB
After deleting rows from DB, database size on the disk was still same, where it should be changed. It is because vacuum was not executed [1]. With this command, size will be changed. [1] https://www.sqlite.org/lang_vacuum.html Change-Id: I33cb868e66fe79f16f893ccf698cbd62a033d61b
This commit is contained in:
@@ -284,6 +284,7 @@ class BuildCache:
|
||||
|
||||
# clean builds that are older than 1 day
|
||||
self.clean()
|
||||
self.vacuum()
|
||||
|
||||
rows = self.fetch_data()
|
||||
if rows:
|
||||
@@ -315,6 +316,10 @@ class BuildCache:
|
||||
def add(self, uid):
|
||||
self.builds[uid] = int(datetime.datetime.now().timestamp())
|
||||
|
||||
def vacuum(self):
|
||||
self.cursor.execute("vacuum")
|
||||
self.connection.commit()
|
||||
|
||||
def clean(self):
|
||||
# Remove old builds
|
||||
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||
|
||||
@@ -566,7 +566,7 @@ class TestBuildCache(base.TestCase):
|
||||
mock_execute = mock_connect.return_value.cursor.return_value.execute
|
||||
mock_execute.assert_called()
|
||||
self.assertEqual('SELECT uid, timestamp FROM logscraper',
|
||||
mock_execute.call_args_list[2].args[0])
|
||||
mock_execute.call_args_list[3].args[0])
|
||||
|
||||
def test_clean(self):
|
||||
# add old data
|
||||
|
||||
Reference in New Issue
Block a user