Remove automatic sqlite vacuum (#12728)

This commit is contained in:
Anders Melchiorsen 2018-02-27 07:41:37 +01:00 committed by Paulus Schoutsen
parent 98fef81d19
commit c1c23bb4b6
3 changed files with 11 additions and 10 deletions

View file

@ -165,7 +165,6 @@ class Recorder(threading.Thread):
self.hass = hass
self.keep_days = keep_days
self.purge_interval = purge_interval
self.did_vacuum = False
self.queue = queue.Queue() # type: Any
self.recording_start = dt_util.utcnow()
self.db_url = uri
@ -269,7 +268,7 @@ class Recorder(threading.Thread):
def async_purge(now):
"""Trigger the purge and schedule the next run."""
self.queue.put(
PurgeTask(self.keep_days, repack=not self.did_vacuum))
PurgeTask(self.keep_days, repack=False))
self.hass.helpers.event.async_track_point_in_time(
async_purge, now + timedelta(days=self.purge_interval))

View file

@ -66,6 +66,5 @@ def purge_old_data(instance, purge_days, repack):
_LOGGER.debug("Vacuuming SQLite to free space")
try:
instance.engine.execute("VACUUM")
instance.did_vacuum = True
except exc.OperationalError as err:
_LOGGER.error("Error vacuuming SQLite: %s.", err)

View file

@ -2,6 +2,7 @@
import json
from datetime import datetime, timedelta
import unittest
from unittest.mock import patch
from homeassistant.components import recorder
from homeassistant.components.recorder.const import DATA_INSTANCE
@ -199,10 +200,12 @@ class TestRecorderPurge(unittest.TestCase):
event.event_type for event in events.all()))
# run purge method - correct service data, with repack
with patch('homeassistant.components.recorder.purge._LOGGER') \
as mock_logger:
service_data['repack'] = True
self.assertFalse(self.hass.data[DATA_INSTANCE].did_vacuum)
self.hass.services.call('recorder', 'purge',
service_data=service_data)
self.hass.block_till_done()
self.hass.data[DATA_INSTANCE].block_till_done()
self.assertTrue(self.hass.data[DATA_INSTANCE].did_vacuum)
self.assertEqual(mock_logger.debug.mock_calls[4][1][0],
"Vacuuming SQLite to free space")