9470a127f7
build / build (push) Successful in 1m11s
统一AI分析入口及双任务安全确认,采用全量载入的可见行渲染,保留完整原文。 右侧非模态详情固定五项质量字段,清理冗余展示并对齐查询和同步按钮。 默认4并发由数据库准入与逐任务租约保护,保留共享限流冷却、截断归因和有界重试。 兼容真实引用标题字段,不伪造证据或准确率,不修改源生产问答与公司区域规则。 验证:完整make verify退出0,710项Go通过、124项已声明可选跳过且必需0跳过; 另全量mirror隔离PostgreSQL race退出0,AI单元race退出0。 真实本地浏览器通过六项交互、390px内滚动及显式AI部分失败/零缺口故障夹具。 治理原生备份已真实恢复,schema57、72表计数与29张QA内容哈希一致。 候选镜像、精确提交CI与正式上线验收待本次提交后执行,不宣称已部署。
126 lines
4.5 KiB
TypeScript
126 lines
4.5 KiB
TypeScript
import { useEffect, useRef, useState } from 'react'
|
||
import { fetchQAMirrorStatus, mirrorSyncActive, mirrorStateChanged, startQAMirrorSync } from './qaMirror'
|
||
import type { QAMirrorStatus } from './qaMirror'
|
||
import { newOperationID } from './operationKey'
|
||
import './qaMirror.css'
|
||
interface ViewProps {
|
||
status: QAMirrorStatus | null
|
||
error: string
|
||
submitting: boolean
|
||
onSync: () => void
|
||
}
|
||
export function QAMirrorSyncView(p: ViewProps) {
|
||
const s = p.status
|
||
const active = mirrorSyncActive(s)
|
||
return (
|
||
<section className="qa-mirror-sync" aria-label="问答同步状态">
|
||
<div className="qa-mirror-sync-line">
|
||
<button
|
||
className="qa-query-action"
|
||
type="button"
|
||
onClick={p.onSync}
|
||
disabled={p.submitting || !s?.worker_ready || active}
|
||
>
|
||
{p.submitting ? '正在入队…' : active ? '后台同步中…' : '立即同步'}
|
||
</button>
|
||
</div>
|
||
<div role="status" className="qa-ops-muted">
|
||
{!s
|
||
? '正在读取同步状态…'
|
||
: s.blocked
|
||
? '源端权限校验未通过,本地读取已阻断;修复授权后可重新同步。'
|
||
: !s.ready
|
||
? '首次同步尚未完成,暂不把未同步数据视为空结果。'
|
||
: ''}
|
||
{s?.job && active ? (
|
||
<span>
|
||
{' '}
|
||
{s.job.expected > 0
|
||
? `已检查 ${s.job.loaded} / ${s.job.expected} 条,取回变化 ${s.job.changed} 条。`
|
||
: '正在检查源端变化。'}
|
||
</span>
|
||
) : null}
|
||
{s?.error_code && s.error_code !== 'initial_sync_pending' && !s.blocked ? (
|
||
<span className="qa-ops-warning"> 最近同步失败,保留上次成功数据;请检查源端连接后重试。</span>
|
||
) : null}
|
||
{s && !s.worker_ready ? <span className="qa-ops-warning"> 同步执行器未在线。</span> : null}
|
||
</div>
|
||
{p.error ? (
|
||
<p className="error-banner" role="alert">
|
||
{p.error}
|
||
</p>
|
||
) : null}
|
||
</section>
|
||
)
|
||
}
|
||
export function QAMirrorSync({ onChanged }: { onChanged: () => void }) {
|
||
const [status, setStatus] = useState<QAMirrorStatus | null>(null),
|
||
[error, setError] = useState(''),
|
||
[submitting, setSubmitting] = useState(false)
|
||
const key = useRef('')
|
||
const acceptedJob = useRef('')
|
||
const changed = useRef(onChanged)
|
||
changed.current = onChanged
|
||
const observed = useRef<{ revision: number; blocked: boolean; ready: boolean } | undefined>(undefined)
|
||
const kick = useRef<() => void>(() => {})
|
||
useEffect(() => {
|
||
let disposed = false,
|
||
timer: ReturnType<typeof setTimeout> | undefined
|
||
const controller = new AbortController()
|
||
let inFlight = false
|
||
const read = async () => {
|
||
if (disposed || inFlight) return
|
||
inFlight = true
|
||
let next = 15000
|
||
try {
|
||
const fresh = await fetchQAMirrorStatus(controller.signal)
|
||
if (disposed) return
|
||
const previous = observed.current
|
||
observed.current = { revision: fresh.revision, blocked: fresh.blocked, ready: fresh.ready }
|
||
setStatus(fresh)
|
||
setError('')
|
||
if (mirrorStateChanged(previous, fresh)) changed.current()
|
||
if (!mirrorSyncActive(fresh) && fresh.job?.id === acceptedJob.current) {
|
||
key.current = ''
|
||
acceptedJob.current = ''
|
||
}
|
||
if (mirrorSyncActive(fresh) || !fresh.ready) next = 2500
|
||
} catch (e) {
|
||
if (!disposed) setError(e instanceof Error ? e.message : '本地同步状态读取失败')
|
||
} finally {
|
||
inFlight = false
|
||
if (!disposed) {
|
||
clearTimeout(timer)
|
||
timer = setTimeout(() => void read(), next)
|
||
}
|
||
}
|
||
}
|
||
kick.current = () => {
|
||
clearTimeout(timer)
|
||
void read()
|
||
}
|
||
void read()
|
||
return () => {
|
||
disposed = true
|
||
controller.abort()
|
||
clearTimeout(timer)
|
||
kick.current = () => {}
|
||
}
|
||
}, [])
|
||
const synchronize = async () => {
|
||
if (submitting || mirrorSyncActive(status)) return
|
||
setSubmitting(true)
|
||
setError('')
|
||
if (!key.current) key.current = newOperationID()
|
||
try {
|
||
acceptedJob.current = await startQAMirrorSync(key.current)
|
||
kick.current()
|
||
} catch (e) {
|
||
setError(e instanceof Error ? e.message : '同步请求未确认,请重试,已有本地数据不变')
|
||
} finally {
|
||
setSubmitting(false)
|
||
}
|
||
}
|
||
return <QAMirrorSyncView status={status} error={error} submitting={submitting} onSync={() => void synchronize()} />
|
||
}
|