fix: iterator exhausted by debug log prevents event cleanup (#22469)

In both expire_snapshots() and expire_clips(), the expired_events
query uses .iterator() for lazy evaluation, but the very next line
calls list(expired_events) inside an f-string for debug logging.
This consumes the entire iterator, so the subsequent for loop that
deletes media files from disk iterates over an exhausted iterator
and processes zero events.

Snapshots and clips for removed cameras are never deleted from disk,
causing gradual disk space exhaustion.

Materialize the iterator into a list before logging so both the
debug message and the cleanup loop use the same data.
This commit is contained in:
ryzendigo 2026-03-16 20:48:35 +08:00 committed by GitHub
parent 6d7b1ce384
commit 7485b48f0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,7 +95,8 @@ class EventCleanup(threading.Thread):
.namedtuples()
.iterator()
)
logger.debug(f"{len(list(expired_events))} events can be expired")
expired_events = list(expired_events)
logger.debug(f"{len(expired_events)} events can be expired")
# delete the media from disk
for expired in expired_events:
@ -220,7 +221,8 @@ class EventCleanup(threading.Thread):
.namedtuples()
.iterator()
)
logger.debug(f"{len(list(expired_events))} events can be expired")
expired_events = list(expired_events)
logger.debug(f"{len(expired_events)} events can be expired")
# delete the media from disk
for expired in expired_events:
media_name = f"{expired.camera}-{expired.id}"