perf: 쿠팡·배송·경비·말레이시아·휴가 라우터 async def → def
동기 psycopg/파일 I/O 를 async def 안에서 부르면 쿼리·엑셀 파싱 동안 이벤트 루프가 멈춰 앱 전체(다른 모듈 포함) 요청이 줄줄이 대기했다. sync def 로 두면 FastAPI 가 스레드풀에서 돌린다. - await 없는 핸들러 116개는 async 키워드만 제거(AST 로 기계 변환). - 업로드: await up.read() → up.file.read() (쿠팡 매출/발주 업로드, 경비 첨부 청크 읽기). - 말레이시아 폼 핸들러 6개: request.form() 은 async 라 _request_form 의존성(인증 뒤에 실행)으로 미리 받아 넘기고 본문은 def. - Google Sheets writer: httplib2 가 스레드 안전하지 않고 같은 날짜 시트를 동시에 쓰면 섞이므로 RLock 으로 직렬화. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -193,7 +193,7 @@ def _save_upload(upload: UploadFile | None, *, dest_dir: Path, slot: tuple) -> s
|
||||
# 배치 목록 (메인)
|
||||
# ════════════════════════════════════════════════════════════
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
async def batches_index(request: Request) -> HTMLResponse:
|
||||
def batches_index(request: Request) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
|
||||
guard = _guard(request)
|
||||
@@ -216,7 +216,7 @@ async def batches_index(request: Request) -> HTMLResponse:
|
||||
|
||||
|
||||
@router.get("/batches/new", response_class=HTMLResponse)
|
||||
async def batch_new(request: Request) -> HTMLResponse:
|
||||
def batch_new(request: Request) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
|
||||
guard = _guard(request)
|
||||
@@ -237,7 +237,7 @@ async def batch_new(request: Request) -> HTMLResponse:
|
||||
|
||||
|
||||
@router.post("/batches")
|
||||
async def batch_create(
|
||||
def batch_create(
|
||||
request: Request,
|
||||
dispatch_date: str = Form(...),
|
||||
platform: str = Form("TikTok"),
|
||||
@@ -321,7 +321,7 @@ async def batch_create(
|
||||
|
||||
|
||||
@router.post("/batches/{batch_id:int}/delete")
|
||||
async def batch_delete(
|
||||
def batch_delete(
|
||||
request: Request, batch_id: int, user: dict[str, Any] = Depends(_require_user)
|
||||
) -> RedirectResponse:
|
||||
"""배치 삭제 — 슈퍼 관리자 전용(박스/상품/로그 CASCADE)."""
|
||||
@@ -338,7 +338,7 @@ async def batch_delete(
|
||||
|
||||
|
||||
@router.get("/batches/{batch_id:int}/download")
|
||||
async def batch_download(
|
||||
def batch_download(
|
||||
request: Request, batch_id: int, user: dict[str, Any] = Depends(_require_user)
|
||||
) -> Response:
|
||||
"""배치 다운로드: 업로드 원본(라벨 PDF + 데이터 엑셀) + 취합 출고 엑셀을 zip 으로 묶음."""
|
||||
@@ -406,7 +406,7 @@ async def batch_download(
|
||||
|
||||
|
||||
@router.get("/stock-export")
|
||||
async def stock_export(
|
||||
def stock_export(
|
||||
request: Request, date: str, user: dict[str, Any] = Depends(_require_user)
|
||||
) -> Response:
|
||||
"""선택한 날짜의 전 배치 출고 수량을 낱개로 분해해 사방넷 재고 업로드 xlsx 다운로드.
|
||||
@@ -478,7 +478,7 @@ async def stock_export(
|
||||
|
||||
|
||||
@router.post("/stock-deduct")
|
||||
async def stock_deduct(
|
||||
def stock_deduct(
|
||||
request: Request,
|
||||
date: str = Form(...),
|
||||
user: dict[str, Any] = Depends(_require_user),
|
||||
@@ -599,7 +599,7 @@ async def stock_deduct(
|
||||
# 출고 작업 리스트 (1박스 = 1카드)
|
||||
# ════════════════════════════════════════════════════════════
|
||||
@router.get("/batches/{batch_id:int}", response_class=HTMLResponse)
|
||||
async def batch_detail(request: Request, batch_id: int) -> HTMLResponse:
|
||||
def batch_detail(request: Request, batch_id: int) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
@@ -631,7 +631,7 @@ async def batch_detail(request: Request, batch_id: int) -> HTMLResponse:
|
||||
|
||||
|
||||
@router.get("/batches/{batch_id:int}/picking", response_class=HTMLResponse)
|
||||
async def batch_picking(request: Request, batch_id: int) -> HTMLResponse:
|
||||
def batch_picking(request: Request, batch_id: int) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
@@ -662,7 +662,7 @@ async def batch_picking(request: Request, batch_id: int) -> HTMLResponse:
|
||||
|
||||
|
||||
@router.get("/batches/{batch_id:int}/handover", response_class=HTMLResponse)
|
||||
async def batch_handover(request: Request, batch_id: int) -> HTMLResponse:
|
||||
def batch_handover(request: Request, batch_id: int) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
@@ -695,7 +695,7 @@ async def batch_handover(request: Request, batch_id: int) -> HTMLResponse:
|
||||
# 상태 토글 (AJAX) + JSON API
|
||||
# ════════════════════════════════════════════════════════════
|
||||
@router.post("/parcels/{parcel_id:int}/toggle")
|
||||
async def parcel_toggle(
|
||||
def parcel_toggle(
|
||||
request: Request,
|
||||
parcel_id: int,
|
||||
field: str = Form(...),
|
||||
@@ -717,7 +717,7 @@ async def parcel_toggle(
|
||||
|
||||
|
||||
@router.post("/batches/{batch_id:int}/bulk")
|
||||
async def parcels_bulk(
|
||||
def parcels_bulk(
|
||||
request: Request,
|
||||
batch_id: int,
|
||||
field: str = Form(...),
|
||||
@@ -739,7 +739,7 @@ async def parcels_bulk(
|
||||
|
||||
|
||||
@router.get("/api/batches/{batch_id:int}/parcels")
|
||||
async def api_parcels(
|
||||
def api_parcels(
|
||||
request: Request, batch_id: int, _: dict[str, Any] = Depends(_require_user)
|
||||
) -> JSONResponse:
|
||||
st = _store(request)
|
||||
@@ -749,7 +749,7 @@ async def api_parcels(
|
||||
|
||||
|
||||
@router.get("/api/search")
|
||||
async def api_search(
|
||||
def api_search(
|
||||
request: Request, q: str = "", _: dict[str, Any] = Depends(_require_user)
|
||||
) -> JSONResponse:
|
||||
"""주문번호/패키지번호/송장번호(부분 일치)로 박스 검색 → 받는 사람/배치 반환."""
|
||||
@@ -769,5 +769,5 @@ async def api_search(
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> dict[str, str]:
|
||||
def health() -> dict[str, str]:
|
||||
return {"status": "ok", "module": "dispatch"}
|
||||
|
||||
Reference in New Issue
Block a user