feat: planning pass counts all folders up front for account-wide progress
Before copying, EXAMINE every folder to sum the account's total message count and emit a 'plan' event; progress events now carry account_total so the UI shows a real overall bar, percent and ETA (not just per-folder). - imapx.FolderMessageCount: read-only count of a folder - orchestrator: plan pass + grandTotal, plan event, account_total in progress - web: live progress keyed on account total; PLAN log line; overall bar/ETA Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
@@ -10,9 +10,8 @@ const emptyAccount = { src_login: '', src_pass: '', dst_login: '', dst_pass: ''
|
||||
type LiveProgress = {
|
||||
copied: number
|
||||
skipped: number
|
||||
total: number // account-wide message total from the planning pass (0 if unknown)
|
||||
folder?: string
|
||||
folderDone: number
|
||||
folderTotal: number
|
||||
startTs: number
|
||||
startCount: number
|
||||
speed: number // messages/sec, averaged since the account's run started
|
||||
@@ -37,6 +36,8 @@ function describeEvent(ev: TaskEvent): string {
|
||||
}
|
||||
case 'account_started':
|
||||
return `START #${d.account_id}: ${d.src_login}@${d.src_host}:${d.src_port} → ${d.dst_login}@${d.dst_host}:${d.dst_port}`
|
||||
case 'plan':
|
||||
return `PLAN #${d.account_id} (${d.src_login}): ${d.folders} folders, ${d.total} messages total`
|
||||
case 'account_done':
|
||||
return `DONE #${d.account_id} (${d.src_login} → ${d.dst_login}): copied ${d.copied}, skipped ${d.skipped}, errors ${d.errors}`
|
||||
case 'progress': {
|
||||
@@ -92,7 +93,22 @@ export function TaskDetail({ id }: { id: number }) {
|
||||
const d = (ev.data ?? {}) as Record<string, number | string | undefined>
|
||||
const accId = typeof d.account_id === 'number' ? d.account_id : undefined
|
||||
|
||||
if (ev.type === 'progress' && accId != null) {
|
||||
if (ev.type === 'plan' && accId != null) {
|
||||
const total = Number(d.total ?? 0)
|
||||
const now = Date.now()
|
||||
setLive((prev) => ({
|
||||
...prev,
|
||||
[accId]: {
|
||||
copied: prev[accId]?.copied ?? 0,
|
||||
skipped: prev[accId]?.skipped ?? 0,
|
||||
total,
|
||||
folder: prev[accId]?.folder,
|
||||
startTs: prev[accId]?.startTs ?? now,
|
||||
startCount: prev[accId]?.startCount ?? 0,
|
||||
speed: prev[accId]?.speed ?? 0,
|
||||
},
|
||||
}))
|
||||
} else if (ev.type === 'progress' && accId != null) {
|
||||
const now = Date.now()
|
||||
const copied = Number(d.copied ?? 0)
|
||||
const skipped = Number(d.skipped ?? 0)
|
||||
@@ -108,9 +124,8 @@ export function TaskDetail({ id }: { id: number }) {
|
||||
[accId]: {
|
||||
copied,
|
||||
skipped,
|
||||
total: Number(d.account_total ?? cur?.total ?? 0),
|
||||
folder: d.folder as string | undefined,
|
||||
folderDone: Number(d.folder_done ?? 0),
|
||||
folderTotal: Number(d.folder_total ?? 0),
|
||||
startTs,
|
||||
startCount,
|
||||
speed,
|
||||
@@ -128,7 +143,7 @@ export function TaskDetail({ id }: { id: number }) {
|
||||
}
|
||||
|
||||
// Structural events refresh the persisted view; `progress` is covered by live state.
|
||||
if (['account_started', 'account_test', 'account_done', 'run_started', 'run_done', 'error', 'folder', 'cancelled'].includes(ev.type)) {
|
||||
if (['account_started', 'account_test', 'account_done', 'run_started', 'run_done', 'error', 'folder', 'cancelled', 'plan'].includes(ev.type)) {
|
||||
reload()
|
||||
}
|
||||
}),
|
||||
@@ -434,17 +449,18 @@ export function TaskDetail({ id }: { id: number }) {
|
||||
<td className="progress-cell">
|
||||
{(() => {
|
||||
const lv = live[a.id]
|
||||
if (!lv || !lv.folderTotal) return <span className="muted-note">—</span>
|
||||
const pct = Math.min(100, Math.floor((lv.folderDone / lv.folderTotal) * 100))
|
||||
const eta = lv.speed > 0 ? (lv.folderTotal - lv.folderDone) / lv.speed : Infinity
|
||||
if (!lv || !lv.total) return <span className="muted-note">—</span>
|
||||
const done = lv.copied + lv.skipped
|
||||
const pct = Math.min(100, Math.floor((done / lv.total) * 100))
|
||||
const eta = lv.speed > 0 ? (lv.total - done) / lv.speed : Infinity
|
||||
return (
|
||||
<div className="acct-progress">
|
||||
<div className="pbar">
|
||||
<span className="pbar-fill" style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
<span className="pmeta mono-num">
|
||||
{lv.folder ? `${lv.folder} · ` : ''}
|
||||
{pct}% · {lv.speed >= 1 ? Math.round(lv.speed) : lv.speed.toFixed(1)}/s · ETA {fmtDuration(eta)}
|
||||
{done}/{lv.total} ({pct}%) · {lv.speed >= 1 ? Math.round(lv.speed) : lv.speed.toFixed(1)}/s · ETA {fmtDuration(eta)}
|
||||
{lv.folder ? ` · ${lv.folder}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user