Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make deleting review items delete recordings as well #10707

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions frigate/api/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from datetime import datetime, timedelta
from functools import reduce
from pathlib import Path

import pandas as pd
from flask import Blueprint, jsonify, make_response, request
Expand Down Expand Up @@ -62,6 +63,7 @@ def review():
.order_by(ReviewSegment.start_time.desc())
.limit(limit)
.dicts()
.iterator()
)

return jsonify([r for r in review])
Expand Down Expand Up @@ -334,15 +336,53 @@ def set_not_reviewed(id):
)


@ReviewBp.route("/reviews/<ids>", methods=("DELETE",))
def delete_reviews(ids: str):
list_of_ids = ids.split(",")
@ReviewBp.route("/reviews/delete", methods=("POST",))
def delete_reviews():
json: dict[str, any] = request.get_json(silent=True) or {}
list_of_ids = json.get("ids", "")

if not list_of_ids or len(list_of_ids) == 0:
return make_response(
jsonify({"success": False, "message": "Not a valid list of ids"}), 404
)

reviews = (
ReviewSegment.select(
ReviewSegment.camera,
ReviewSegment.start_time,
ReviewSegment.end_time,
)
.where(ReviewSegment.id << list_of_ids)
.dicts()
.iterator()
)
recording_ids = []

for review in reviews:
start_time = review["start_time"]
end_time = review["end_time"]
camera_name = review["camera"]
recordings = (
Recordings.select(Recordings.id, Recordings.path)
.where(
Recordings.start_time.between(start_time, end_time)
| Recordings.end_time.between(start_time, end_time)
| (
(start_time > Recordings.start_time)
& (end_time < Recordings.end_time)
)
)
.where(Recordings.camera == camera_name)
.dicts()
.iterator()
)

for recording in recordings:
Path(recording["path"]).unlink(missing_ok=True)
recording_ids.append(recording["id"])

# delete recordings and review segments
Recordings.delete().where(Recordings.id << recording_ids).execute()
ReviewSegment.delete().where(ReviewSegment.id << list_of_ids).execute()

return make_response(jsonify({"success": True, "message": "Delete reviews"}), 200)
Expand Down
3 changes: 1 addition & 2 deletions web/src/components/filter/ReviewActionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export default function ReviewActionGroup({
}, [selectedReviews, setSelectedReviews, pullLatestData]);

const onDelete = useCallback(async () => {
const idList = selectedReviews.join(",");
await axios.delete(`reviews/${idList}`);
await axios.post(`reviews/delete`, { ids: selectedReviews });
setSelectedReviews([]);
pullLatestData();
}, [selectedReviews, setSelectedReviews, pullLatestData]);
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/player/PreviewThumbnailPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export default function PreviewThumbnailPlayer({
} else {
// the second preview is longer, return the second if it exists
if (firstIndex < allPreviews.length - 1) {
return allPreviews[firstIndex + 1];
return allPreviews.find(
(preview, idx) => idx > firstIndex && preview.camera == review.camera,
);
}

return undefined;
Expand Down
Loading