fix: BLS-Import-UI und Timeout beim Daten-Apply
Datei-Button volle Breite, Import als Aktionsbutton, Batch-Upsert statt Einzel-INSERTs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7ccae33844
commit
8e964509d7
7 files changed
+170
-145
No files matched your search
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
from pydantic import BaseModel
|
||||
|
||||
from auth import require_admin
|
||||
@@ -61,14 +62,18 @@ async def import_components(
|
||||
if not raw:
|
||||
raise HTTPException(400, "Leere Datei")
|
||||
try:
|
||||
attrs = parse_components_xlsx(raw)
|
||||
attrs = await run_in_threadpool(parse_components_xlsx, raw)
|
||||
except Exception as e:
|
||||
raise HTTPException(400, f"Components-Datei unlesbar: {e}") from e
|
||||
if dry_run:
|
||||
return {"dry_run": True, "attributes": len(attrs), "sample": attrs[:8]}
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
stats = upsert_attributes(cur, attrs)
|
||||
|
||||
def apply():
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return upsert_attributes(cur, attrs)
|
||||
|
||||
stats = await run_in_threadpool(apply)
|
||||
return {"dry_run": False, **stats}
|
||||
|
||||
|
||||
@@ -82,7 +87,7 @@ async def import_foods(
|
||||
if not raw:
|
||||
raise HTTPException(400, "Leere Datei")
|
||||
try:
|
||||
parsed = parse_foods_xlsx(raw)
|
||||
parsed = await run_in_threadpool(parse_foods_xlsx, raw)
|
||||
except Exception as e:
|
||||
raise HTTPException(400, f"Datendatei unlesbar: {e}") from e
|
||||
foods = parsed["foods"]
|
||||
@@ -96,9 +101,13 @@ async def import_foods(
|
||||
for f in foods[:8]
|
||||
],
|
||||
}
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
stats = upsert_foods(cur, foods)
|
||||
|
||||
def apply():
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return upsert_foods(cur, foods)
|
||||
|
||||
stats = await run_in_threadpool(apply)
|
||||
return {"dry_run": False, **stats}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user