Group search results by owner; auto-resume stuck pending documents

This commit is contained in:
Krikorios
2026-05-07 21:59:29 +03:00
parent 631a4c3e3d
commit 60eb58cc9f
6 changed files with 80 additions and 13 deletions
+21
View File
@@ -233,6 +233,27 @@ async def retry_all_errors():
return JSONResponse({"ok": True, "retried": len(rows)})
@router.post("/documents/resume-pending")
async def resume_pending():
"""Re-fire background extraction for any docs stuck in 'pending'.
Useful when a previous server restart killed in-flight extraction tasks."""
import asyncio
from services.extractor import get_default_provider
from routers.upload import _extract_and_save
default_provider = get_default_provider()
with get_db() as conn:
rows = conn.execute(
"SELECT id, image_path, provider FROM documents WHERE status='pending'"
).fetchall()
for row in rows:
provider = row["provider"] or default_provider
asyncio.create_task(_extract_and_save(row["id"], row["image_path"], provider))
return JSONResponse({"ok": True, "resumed": len(rows)})
@router.post("/documents/scan-duplicates")
async def scan_duplicates():
"""
+2 -5
View File
@@ -31,12 +31,9 @@ async def search(
if property_number or district or block:
properties = search_properties(property_number, district, block)
# If exactly one person found, preload their full details
# If exactly one person found, preload their full details (across all scopes)
if len(persons) == 1 and not properties:
selected_person = get_person_with_properties(
persons[0]["id"],
persons[0].get("search_scope"),
)
selected_person = get_person_with_properties(persons[0]["id"], None)
return render_template(
templates,