Skip to content

Commit

Permalink
Allow empty description for tracked objects (#14271)
Browse files Browse the repository at this point in the history
* Allow tracked object description to be saved as an empty string

* ensure event_ids is passed as list
  • Loading branch information
hawkeye217 authored Oct 10, 2024
1 parent 54eb03d commit 8d753f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
4 changes: 1 addition & 3 deletions frigate/api/defs/events_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class EventsSubLabelBody(BaseModel):


class EventsDescriptionBody(BaseModel):
description: Union[str, None] = Field(
title="The description of the event", min_length=1
)
description: Union[str, None] = Field(title="The description of the event")


class EventsCreateBody(BaseModel):
Expand Down
26 changes: 9 additions & 17 deletions frigate/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,27 +927,19 @@ def set_description(

new_description = body.description

if new_description is None or len(new_description) == 0:
return JSONResponse(
content=(
{
"success": False,
"message": "description cannot be empty",
}
),
status_code=400,
)

event.data["description"] = new_description
event.save()

# If semantic search is enabled, update the index
if request.app.frigate_config.semantic_search.enabled:
context: EmbeddingsContext = request.app.embeddings
context.update_description(
event_id,
new_description,
)
if len(new_description) > 0:
context.update_description(
event_id,
new_description,
)
else:
context.db.delete_embeddings_description(event_ids=[event_id])

response_message = (
f"Event {event_id} description is now blank"
Expand Down Expand Up @@ -1033,8 +1025,8 @@ def delete_event(request: Request, event_id: str):
# If semantic search is enabled, update the index
if request.app.frigate_config.semantic_search.enabled:
context: EmbeddingsContext = request.app.embeddings
context.db.delete_embeddings_thumbnail(id=[event_id])
context.db.delete_embeddings_description(id=[event_id])
context.db.delete_embeddings_thumbnail(event_ids=[event_id])
context.db.delete_embeddings_description(event_ids=[event_id])
return JSONResponse(
content=({"success": True, "message": "Event " + event_id + " deleted"}),
status_code=200,
Expand Down
4 changes: 2 additions & 2 deletions frigate/events/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def run(self) -> None:
Event.delete().where(Event.id << chunk).execute()

if self.config.semantic_search.enabled:
self.db.delete_embeddings_description(chunk)
self.db.delete_embeddings_thumbnail(chunk)
self.db.delete_embeddings_description(event_ids=[chunk])
self.db.delete_embeddings_thumbnail(event_ids=[chunk])
logger.debug(f"Deleted {len(events_to_delete)} embeddings")

logger.info("Exiting event cleanup...")

0 comments on commit 8d753f8

Please sign in to comment.