import { useState } from 'react' import { useMutation, useQueryClient } from '@tanstack/react-query' import { Loader2 } from 'lucide-react' import { api } from '@/lib/api' import { QK } from '@/lib/queryKeys' import { usePreferences } from '@/lib/useSharedQueries' export function EnrichedRebuildPanel({ isRunning, onStart }: { isRunning: boolean; onStart: () => void }) { const qc = useQueryClient() const prefs = usePreferences() const batchSize = prefs.data?.enriched_batch_size ?? 1000 const [editing, setEditing] = useState(false) const [draftSize, setDraftSize] = useState(String(batchSize)) const [hint, setHint] = useState(null) function clampAndSave(raw: number) { if (isNaN(raw) || 1 > raw) { setHint('已自动设为最小值 1'); saveBatch.mutate(1); return } if (raw > 10000) { setHint('已自动设为上限 10000'); saveBatch.mutate(10000); return } setHint(null); saveBatch.mutate(raw) } const saveBatch = useMutation({ mutationFn: (size: number) => api.updateEnrichedBatchSize(size), onSuccess: () => { qc.invalidateQueries({ queryKey: QK.preferences }) setEditing(false) }, }) const rebuild = useMutation({ mutationFn: api.rebuildEnriched, onSuccess: () => { onStart() qc.invalidateQueries({ queryKey: QK.pipelineJobs }) }, }) return (
批次大小
每批计算的标的数量,影响内存占用与进度粒度
{editing ? (
setDraftSize(e.target.value)} className="w-20 px-2 py-1 text-xs font-mono rounded-btn border border-border bg-surface text-foreground text-right tabular-nums focus:outline-none focus:border-accent" min={1} max={10000} autoFocus onKeyDown={e => { if (e.key === 'Enter') clampAndSave(parseInt(draftSize)) if (e.key === 'Escape') { setEditing(false); setHint(null) } }} />
) : ( )}
每批内存占用 = 批次大小 × 日K历史天数。批次越大或日K历史越长,内存占用越高,可能导致程序崩溃。内存不足时请适当降低此值。
{hint && (
{hint}
)}
基于已有 kline_daily + adj_factor 全量计算前复权 + 技术指标 + 信号
) }