mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-06 19:25:22 +03:00
Reduce database queries to necessary labels
This commit is contained in:
parent
5658e5a4cc
commit
3fa5a41b60
@ -83,7 +83,10 @@ class EventCleanup(threading.Thread):
|
|||||||
datetime.datetime.now() - datetime.timedelta(days=expire_days)
|
datetime.datetime.now() - datetime.timedelta(days=expire_days)
|
||||||
).timestamp()
|
).timestamp()
|
||||||
# grab all events after specific time
|
# grab all events after specific time
|
||||||
expired_events = Event.select().where(
|
expired_events = Event.select(
|
||||||
|
Event.id,
|
||||||
|
Event.camera,
|
||||||
|
).where(
|
||||||
Event.camera.not_in(self.camera_keys),
|
Event.camera.not_in(self.camera_keys),
|
||||||
Event.start_time < expire_after,
|
Event.start_time < expire_after,
|
||||||
Event.label == event.label,
|
Event.label == event.label,
|
||||||
|
|||||||
@ -89,7 +89,10 @@ class RecordingCleanup(threading.Thread):
|
|||||||
|
|
||||||
# Get all the events to check against
|
# Get all the events to check against
|
||||||
events: Event = (
|
events: Event = (
|
||||||
Event.select()
|
Event.select(
|
||||||
|
Event.start_time,
|
||||||
|
Event.end_time,
|
||||||
|
)
|
||||||
.where(
|
.where(
|
||||||
Event.camera == camera,
|
Event.camera == camera,
|
||||||
# need to ensure segments for all events starting
|
# need to ensure segments for all events starting
|
||||||
@ -109,7 +112,7 @@ class RecordingCleanup(threading.Thread):
|
|||||||
keep = False
|
keep = False
|
||||||
# Now look for a reason to keep this recording segment
|
# Now look for a reason to keep this recording segment
|
||||||
for idx in range(event_start, len(events)):
|
for idx in range(event_start, len(events)):
|
||||||
event = events[idx]
|
event: Event = events[idx]
|
||||||
|
|
||||||
# if the event starts in the future, stop checking events
|
# if the event starts in the future, stop checking events
|
||||||
# and let this recording segment expire
|
# and let this recording segment expire
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user