improve query

This commit is contained in:
Josh Hawkins 2025-08-13 15:19:48 -05:00
parent c462f4d89f
commit 4e2ab29ea1
2 changed files with 17 additions and 18 deletions

View File

@ -20,7 +20,7 @@ from fastapi.encoders import jsonable_encoder
from fastapi.params import Depends from fastapi.params import Depends
from fastapi.responses import JSONResponse, PlainTextResponse, StreamingResponse from fastapi.responses import JSONResponse, PlainTextResponse, StreamingResponse
from markupsafe import escape from markupsafe import escape
from peewee import operator from peewee import SQL, operator
from pydantic import ValidationError from pydantic import ValidationError
from frigate.api.auth import require_role from frigate.api.auth import require_role
@ -685,7 +685,14 @@ def plusModels(request: Request, filterByCurrentModelDetector: bool = False):
@router.get("/recognized_license_plates") @router.get("/recognized_license_plates")
def get_recognized_license_plates(split_joined: Optional[int] = None): def get_recognized_license_plates(split_joined: Optional[int] = None):
try: try:
events = Event.select(Event.data).distinct() query = (
Event.select(
SQL("json_extract(data, '$.recognized_license_plate') AS plate")
)
.where(SQL("json_extract(data, '$.recognized_license_plate') IS NOT NULL"))
.distinct()
)
recognized_license_plates = [row[0] for row in query.tuples()]
except Exception: except Exception:
return JSONResponse( return JSONResponse(
content=( content=(
@ -694,14 +701,6 @@ def get_recognized_license_plates(split_joined: Optional[int] = None):
status_code=404, status_code=404,
) )
recognized_license_plates = []
for e in events:
if e.data is not None and "recognized_license_plate" in e.data:
recognized_license_plates.append(e.data["recognized_license_plate"])
while None in recognized_license_plates:
recognized_license_plates.remove(None)
if split_joined: if split_joined:
original_recognized_license_plates = recognized_license_plates.copy() original_recognized_license_plates = recognized_license_plates.copy()
for recognized_license_plate in original_recognized_license_plates: for recognized_license_plate in original_recognized_license_plates:

View File

@ -948,11 +948,11 @@ export function RecognizedLicensePlatesFilterContent({
<DropdownMenuSeparator className="mb-3" /> <DropdownMenuSeparator className="mb-3" />
<div className="mb-3 text-lg">{t("recognizedLicensePlates.title")}</div> <div className="mb-3 text-lg">{t("recognizedLicensePlates.title")}</div>
{allRecognizedLicensePlates == undefined ? ( {allRecognizedLicensePlates == undefined ? (
<p className="flex items-center text-sm text-muted-foreground"> <div className="flex flex-col items-center justify-center text-sm text-muted-foreground">
<ActivityIndicator className="mr-2 size-5" /> <ActivityIndicator className="mb-3 mr-2 size-5" />
{t("recognizedLicensePlates.loading")} <p>{t("recognizedLicensePlates.loading")}</p>
</p> </div>
) : allRecognizedLicensePlates.length === 0 ? null : ( ) : allRecognizedLicensePlates.length == 0 ? null : (
<> <>
<Command <Command
className="border border-input bg-background" className="border border-input bg-background"
@ -1007,11 +1007,11 @@ export function RecognizedLicensePlatesFilterContent({
))} ))}
</div> </div>
)} )}
</>
)}
<p className="mt-1 text-sm text-muted-foreground"> <p className="mt-1 text-sm text-muted-foreground">
{t("recognizedLicensePlates.selectPlatesFromList")} {t("recognizedLicensePlates.selectPlatesFromList")}
</p> </p>
</>
)}
</div> </div>
); );
} }