mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-07 11:45:24 +03:00
Performance increase with lots of recordings
This commit is contained in:
parent
cc5357a31a
commit
f85ab14722
@ -1584,20 +1584,10 @@ def recordings_summary(camera_name):
|
|||||||
)
|
)
|
||||||
.where(Recordings.camera == camera_name)
|
.where(Recordings.camera == camera_name)
|
||||||
.group_by(
|
.group_by(
|
||||||
fn.strftime(
|
Recordings.start_time.cast("int") / 3600
|
||||||
"%Y-%m-%d %H",
|
|
||||||
fn.datetime(
|
|
||||||
Recordings.start_time, "unixepoch", hour_modifier, minute_modifier
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.order_by(
|
.order_by(
|
||||||
fn.strftime(
|
Recordings.start_time.desc()
|
||||||
"%Y-%m-%d H",
|
|
||||||
fn.datetime(
|
|
||||||
Recordings.start_time, "unixepoch", hour_modifier, minute_modifier
|
|
||||||
),
|
|
||||||
).desc()
|
|
||||||
)
|
)
|
||||||
.namedtuples()
|
.namedtuples()
|
||||||
)
|
)
|
||||||
@ -1614,12 +1604,7 @@ def recordings_summary(camera_name):
|
|||||||
)
|
)
|
||||||
.where(Event.camera == camera_name, Event.has_clip)
|
.where(Event.camera == camera_name, Event.has_clip)
|
||||||
.group_by(
|
.group_by(
|
||||||
fn.strftime(
|
Event.start_time.cast("int") / 3600
|
||||||
"%Y-%m-%d %H",
|
|
||||||
fn.datetime(
|
|
||||||
Event.start_time, "unixepoch", hour_modifier, minute_modifier
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.namedtuples()
|
.namedtuples()
|
||||||
)
|
)
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class StorageMaintainer(threading.Thread):
|
|||||||
if self.camera_storage_stats.get(camera, {}).get("needs_refresh", True):
|
if self.camera_storage_stats.get(camera, {}).get("needs_refresh", True):
|
||||||
self.camera_storage_stats[camera] = {
|
self.camera_storage_stats[camera] = {
|
||||||
"needs_refresh": (
|
"needs_refresh": (
|
||||||
Recordings.select(fn.COUNT(Recordings.id))
|
Recordings.select(fn.COUNT("*"))
|
||||||
.where(Recordings.camera == camera, Recordings.segment_size > 0)
|
.where(Recordings.camera == camera, Recordings.segment_size > 0)
|
||||||
.scalar()
|
.scalar()
|
||||||
< 50
|
< 50
|
||||||
|
|||||||
44
migrations/020_update_index_recordings.py
Normal file
44
migrations/020_update_index_recordings.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
"""Peewee migrations -- 011_update_indexes.py.
|
||||||
|
|
||||||
|
Some examples (model - class or model name)::
|
||||||
|
|
||||||
|
> Model = migrator.orm['model_name'] # Return model in current state by name
|
||||||
|
|
||||||
|
> migrator.sql(sql) # Run custom SQL
|
||||||
|
> migrator.python(func, *args, **kwargs) # Run python code
|
||||||
|
> migrator.create_model(Model) # Create a model (could be used as decorator)
|
||||||
|
> migrator.remove_model(model, cascade=True) # Remove a model
|
||||||
|
> migrator.add_fields(model, **fields) # Add fields to a model
|
||||||
|
> migrator.change_fields(model, **fields) # Change fields
|
||||||
|
> migrator.remove_fields(model, *field_names, cascade=True)
|
||||||
|
> migrator.rename_field(model, old_field_name, new_field_name)
|
||||||
|
> migrator.rename_table(model, new_table_name)
|
||||||
|
> migrator.add_index(model, *col_names, unique=False)
|
||||||
|
> migrator.drop_index(model, *col_names)
|
||||||
|
> migrator.add_not_null(model, *field_names)
|
||||||
|
> migrator.drop_not_null(model, *field_names)
|
||||||
|
> migrator.add_default(model, field_name, default)
|
||||||
|
|
||||||
|
"""
|
||||||
|
import peewee as pw
|
||||||
|
|
||||||
|
SQL = pw.SQL
|
||||||
|
|
||||||
|
|
||||||
|
def migrate(migrator, database, fake=False, **kwargs):
|
||||||
|
migrator.sql(
|
||||||
|
'DROP INDEX recordings_end_time_start_time'
|
||||||
|
)
|
||||||
|
migrator.sql(
|
||||||
|
'CREATE INDEX "recordings_camera_start_time_end_time" ON "recordings" ("camera", "start_time" DESC, "end_time" DESC)'
|
||||||
|
)
|
||||||
|
migrator.sql(
|
||||||
|
'CREATE INDEX "recordings_api_recordings_summary" ON "recordings" ("camera", "start_time" DESC, "duration", "motion", "objects")'
|
||||||
|
)
|
||||||
|
migrator.sql(
|
||||||
|
'CREATE INDEX "recordings_start_time" ON "recordings" ("start_time")'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def rollback(migrator, database, fake=False, **kwargs):
|
||||||
|
pass
|
||||||
Loading…
Reference in New Issue
Block a user