Implemented efficient re-exporting

This commit is contained in:
patben8 committed 2026-09-28 20:44:14 +02:00
1 parent 3a9dc90344
commit bb9f6e2bd3
14 files changed
+727 -63

No files matched your search

+6
View File
@@ -399,6 +399,9 @@ export interface JobStatus {
/** 0 until the job knows its size — show an indeterminate bar until positive. */
total: number
done: number
/** What done/total count: 'bytes' while copying, 'tracks' while a library
* is written; '' when unspecified. */
unit: string
message: string
result: Record<string, unknown> | null
error: string | null
@@ -487,6 +490,9 @@ export interface ExportContents {
export interface ExportPreview {
tracks: number
exportable: number
/** Tracks whose copy from the last export is still current, so are kept
* rather than copied. `total_bytes` counts only what WILL be copied. */
unchanged: number
missing: string[]
playlists: string[]
total_bytes: number
+33 -7
View File
@@ -59,11 +59,12 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
if (next.state !== 'running') {
if (pollRef.current) window.clearInterval(pollRef.current)
if (next.state === 'done') {
const r = next.result as { tracks?: number; playlists?: number } | null
const r = next.result as { tracks?: number; playlists?: number; unchanged?: number } | null
qc.invalidateQueries({ queryKey: ['export-contents', set.id] })
onDone(
`Exported ${r?.tracks ?? 0} track${r?.tracks === 1 ? '' : 's'}` +
(r?.playlists ? ` and ${r.playlists} playlist${r.playlists === 1 ? '' : 's'}` : ''),
(r?.playlists ? ` and ${r.playlists} playlist${r.playlists === 1 ? '' : 's'}` : '') +
(r?.unchanged ? ` (${r.unchanged} unchanged)` : ''),
)
} else if (next.state === 'failed') {
onError(next.error || 'Export failed')
@@ -102,7 +103,14 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
const p = preview.data
const running = job?.state === 'running'
const finished = job != null && job.state !== 'running'
const pct = job && job.total > 0 ? Math.min(100, (job.done / job.total) * 100) : null
// A finished export is a full bar, whatever the last phase reported — a
// re-export that copied nothing never had a byte count to fill.
const pct =
job?.state === 'done'
? 100
: job && job.total > 0
? Math.min(100, (job.done / job.total) * 100)
: null
const blocked = p?.blocked ?? null
return createPortal(
@@ -137,7 +145,9 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
{p.exportable} track{p.exportable === 1 ? '' : 's'}
{p.playlists.length > 0 &&
` · ${p.playlists.length} playlist${p.playlists.length === 1 ? '' : 's'}`}
<span className="text-muted"> · {gb(p.total_bytes)} to copy</span>
<span className="text-muted">
{p.unchanged > 0 && ` · ${p.unchanged} unchanged`} · {gb(p.total_bytes)} to copy
</span>
</div>
{p.free_bytes != null && (
<div className={p.enough_space === false ? 'text-pink' : 'text-faint'}>
@@ -156,7 +166,7 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
)}
{p.replacing && (
<div className="rounded well px-3 py-2 text-xs text-gold">
This folder already holds an export. Its files will be replaced.
This folder already holds an export. Tracks that haven’t changed are kept; everything else is replaced.
</div>
)}
{/* A warning, not a block: the other targets are fine anywhere,
@@ -207,7 +217,9 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
{job && (
<div className="space-y-3">
<div className="text-text">{job.message || 'Working…'}</div>
<div className="text-text">
{job.state === 'done' ? finishedLine(job.result) : job.message || 'Working…'}
</div>
<div className="h-2 overflow-hidden rounded-full bg-well">
<div
className={`h-full transition-[width] duration-200 ${
@@ -216,7 +228,8 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
style={pct == null ? undefined : { width: `${pct}%` }}
/>
</div>
{pct != null && running && (
{/* Tracks say their count in the message ("Analysing … (12/207)"). */}
{pct != null && running && job.unit === 'bytes' && (
<div className="text-xs text-faint">
{gb(job.done)} of {gb(job.total)}
</div>
@@ -293,3 +306,16 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
document.body,
)
}
/** "207 tracks exported — 207 unchanged, nothing copied." Worded from the result's counts. */
function finishedLine(result: Record<string, unknown> | null): string {
const r = (result ?? {}) as { tracks?: number; unchanged?: number }
const tracks = r.tracks ?? 0
const unchanged = r.unchanged ?? 0
const head = `${tracks} track${tracks === 1 ? '' : 's'} exported`
if (!unchanged) return head
const copied = tracks - unchanged
return `${head} — ${unchanged} unchanged, ${
copied ? `${copied} copied` : 'nothing copied'
}`
}