Background long-running actions; confirm destructive ones

- Run now (jobs and playlists), dedup scan, genre preview/apply, and manual
  import now dispatch via BackgroundTasks and redirect immediately, instead
  of awaiting a job that can run for the better part of an hour and hang the
  browser or reverse proxy. Progress shows in the Jobs runs table (which
  already polls); if the pipeline is busy the run records skipped_lock there.
- Fix the import banner, which claimed work was ongoing after the request
  had actually blocked to completion; it now reflects the backgrounded start.
- Add confirmation prompts to the dedup per-row and bulk delete and to
  "Fix genres now", matching the existing confirms on library and playlist
  deletes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
andrew
2026-07-09 14:31:54 -06:00
parent b135f11557
commit 8f1fc458f6
8 changed files with 61 additions and 43 deletions
+9 -8
View File
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, Request
from fastapi import APIRouter, BackgroundTasks, Depends, Request
from fastapi.responses import RedirectResponse
from fastapi.templating import Jinja2Templates
@@ -53,14 +53,15 @@ async def dedup_index(request: Request, user: dict = Depends(require_auth)):
@router.post("/scan")
async def scan(user: dict = Depends(require_auth)):
async def scan(background: BackgroundTasks, user: dict = Depends(require_auth)):
# Runs both the file-naming and acoustic passes -- see
# dedup_review_service.scan_all(). The candidates table shows which
# pass caught each one instead of needing two separate buttons.
tag_run, fuzzy_run = await dedup_review_service.scan_all(triggered_by="manual")
if tag_run is None or fuzzy_run is None:
return RedirectResponse(url="/dedup?skipped=1", status_code=303)
return RedirectResponse(url="/dedup", status_code=303)
# dedup_review_service.scan_all(). The acoustic pass can take a while on a
# large library, so run it in the background and return immediately; the
# candidates appear here once it finishes (reload), and the run shows up
# under Settings then Jobs. If the pipeline is busy it records skipped_lock
# there rather than blocking.
background.add_task(dedup_review_service.scan_all, triggered_by="manual")
return RedirectResponse(url="/dedup?started=1", status_code=303)
@router.post("/confirm")