mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-12-23 19:11:14 +01:00
Fix: Add limit to event query (#7108)
* Add limit to event query for fetching latest event with specified label and camera name * Refactor the label_thumbnail function in frigate/http.py to simplify the event_query logic and improve code readability
This commit is contained in:
parent
5c12762cb5
commit
6ac36e8436
@ -593,24 +593,14 @@ def timeline():
|
||||
@bp.route("/<camera_name>/<label>/thumbnail.jpg")
|
||||
def label_thumbnail(camera_name, label):
|
||||
label = unquote(label)
|
||||
if label == "any":
|
||||
event_query = (
|
||||
Event.select()
|
||||
.where(Event.camera == camera_name)
|
||||
.order_by(Event.start_time.desc())
|
||||
)
|
||||
else:
|
||||
event_query = (
|
||||
Event.select()
|
||||
.where(Event.camera == camera_name)
|
||||
.where(Event.label == label)
|
||||
.order_by(Event.start_time.desc())
|
||||
)
|
||||
event_query = Event.select(fn.MAX(Event.id)).where(Event.camera == camera_name)
|
||||
if label != "any":
|
||||
event_query = event_query.where(Event.label == label)
|
||||
|
||||
try:
|
||||
event = event_query.get()
|
||||
event = event_query.scalar()
|
||||
|
||||
return event_thumbnail(event.id, 60)
|
||||
return event_thumbnail(event, 60)
|
||||
except DoesNotExist:
|
||||
frame = np.zeros((175, 175, 3), np.uint8)
|
||||
ret, jpg = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
||||
|
Loading…
Reference in New Issue
Block a user