DB Optimizations (#6712)

* Enable auto vacuums

* Enable auto vacuum

* Fix separator

* Fix separator and remove incorrect log

* Limit to 1 row since that is all that is used

* Add index on camera + segment_size

* Formatting

* Increase timeout and cache_size

* Set DB mode to NORMAL synchronous level

* Formatting

* Vacuum every 2 weeks

* Remove fstring

* Use string

* Use consts
This commit is contained in:
Nicolas Mowen
2023-06-11 06:23:18 -06:00
committed by GitHub
parent 20b52a96bc
commit 8bc76d19db
5 changed files with 87 additions and 9 deletions

View File

@@ -36,9 +36,7 @@ class StorageMaintainer(threading.Thread):
self.camera_storage_stats[camera] = {
"needs_refresh": (
Recordings.select(fn.COUNT(Recordings.id))
.where(
Recordings.camera == camera, Recordings.segment_size != 0
)
.where(Recordings.camera == camera, Recordings.segment_size > 0)
.scalar()
< 50
)
@@ -48,7 +46,7 @@ class StorageMaintainer(threading.Thread):
try:
bandwidth = round(
Recordings.select(fn.AVG(bandwidth_equation))
.where(Recordings.camera == camera, Recordings.segment_size != 0)
.where(Recordings.camera == camera, Recordings.segment_size > 0)
.limit(100)
.scalar()
* 3600,
@@ -178,6 +176,7 @@ class StorageMaintainer(threading.Thread):
def run(self):
"""Check every 5 minutes if storage needs to be cleaned up."""
self.calculate_camera_bandwidth()
while not self.stop_event.wait(300):
if not self.camera_storage_stats or True in [
r["needs_refresh"] for r in self.camera_storage_stats.values()