列表正文改为按需读取;保留完整导出、版本隔离和有效标签筛选。 验证:前端全量、Go全量及隔离PG全mirror竞态通过;覆盖首批回调、续载失败与筛选分页。
This commit is contained in:
+32
-2
@@ -78,12 +78,14 @@ export function mergeQAPages(current: QARecordPage, next: QARecordPage): QARecor
|
||||
current.organization?.revision_id !== next.organization?.revision_id
|
||||
)
|
||||
throw new Error('通讯录或区域配置已变化,请重新查询,不能混合不同版本的分页结果')
|
||||
const ids = new Set(current.items.map((item) => item.id))
|
||||
return {
|
||||
...next,
|
||||
items: [...current.items, ...next.items.filter((item) => !current.items.some((old) => old.id === item.id))],
|
||||
items: [...current.items, ...next.items.filter((item) => !ids.has(item.id))],
|
||||
}
|
||||
}
|
||||
export interface QARecord {
|
||||
content_projection?: 'summary'
|
||||
field_edit_revision?: number
|
||||
background_tasks?: AIWorkState[]
|
||||
record_origin?: 'dobotai_2_0' | 'historical_excel'
|
||||
@@ -128,6 +130,8 @@ export interface QARecordPage {
|
||||
as_of: string
|
||||
}
|
||||
export interface QAQuery {
|
||||
projection?: 'summary' | 'full'
|
||||
filters?: Partial<Record<'coverage' | 'is_correct' | 'product_category' | 'problem_type' | 'root_cause', string>>
|
||||
dataset?: 'master'
|
||||
start: string
|
||||
end: string
|
||||
@@ -135,6 +139,25 @@ export interface QAQuery {
|
||||
cursor: string
|
||||
limit?: number
|
||||
}
|
||||
export function qualityFiltersKey(filters: QAQuery['filters']): string {
|
||||
return JSON.stringify(Object.entries(filters ?? {}).sort(([a], [b]) => a.localeCompare(b)))
|
||||
}
|
||||
export function parseQualityFilters(value: unknown): NonNullable<QAQuery['filters']> {
|
||||
if (value === undefined) return {}
|
||||
const fields = object(value),
|
||||
out: NonNullable<QAQuery['filters']> = {}
|
||||
for (const [key, v] of Object.entries(fields)) {
|
||||
if (
|
||||
!['coverage', 'is_correct', 'product_category', 'problem_type', 'root_cause'].includes(key) ||
|
||||
typeof v !== 'string' ||
|
||||
!v ||
|
||||
v.length > 400
|
||||
)
|
||||
return invalid()
|
||||
out[key as keyof typeof out] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
export interface QAStatus {
|
||||
state: 'disabled' | 'unavailable' | 'blocked' | 'connected'
|
||||
code: string
|
||||
@@ -163,6 +186,7 @@ const columnKeys = new Set<string>(qaColumns.map(({ key }) => key))
|
||||
|
||||
export function parseQARecord(value: unknown): QARecord {
|
||||
const row = object(value)
|
||||
if (row.content_projection !== undefined && row.content_projection !== 'summary') return invalid()
|
||||
const feedback = object(row.feedback)
|
||||
const source = object(row.source_coverage)
|
||||
const coverage = object(row.coverage)
|
||||
@@ -182,6 +206,7 @@ export function parseQARecord(value: unknown): QARecord {
|
||||
const askerValue = text(feedback.asker_value)
|
||||
if (!['', 'up', 'down'].includes(askerValue)) return invalid()
|
||||
const item: QARecord = {
|
||||
...(row.content_projection === 'summary' ? { content_projection: 'summary' as const } : {}),
|
||||
...(row.quality === undefined
|
||||
? {}
|
||||
: {
|
||||
@@ -332,12 +357,15 @@ export async function fetchQARecords(query: QAQuery, signal?: AbortSignal): Prom
|
||||
cursor: query.cursor,
|
||||
limit: String(query.limit ?? 20),
|
||||
})
|
||||
if (query.projection) parameters.set('projection', query.projection)
|
||||
for (const [key, value] of Object.entries(query.filters ?? {})) if (value) parameters.set(key, value)
|
||||
return parseQARecordPage(await getPayload(`${qaDatasetPrefix(query.dataset)}/records?${parameters}`, signal))
|
||||
}
|
||||
export async function fetchAllQARecords(
|
||||
query: QAQuery,
|
||||
signal?: AbortSignal,
|
||||
onProgress?: (loaded: number, total: number) => void
|
||||
onProgress?: (loaded: number, total: number) => void,
|
||||
onPage?: (page: QARecordPage) => void
|
||||
): Promise<QARecordPage> {
|
||||
if (signal?.aborted) throw new DOMException('读取已取消', 'AbortError')
|
||||
let page = await fetchQARecords({ ...query, cursor: '', limit: 100 }, signal)
|
||||
@@ -345,6 +373,7 @@ export async function fetchAllQARecords(
|
||||
const ids = new Set(page.items.map((item) => item.id))
|
||||
const cursors = new Set<string>()
|
||||
onProgress?.(ids.size, total)
|
||||
onPage?.(page)
|
||||
while (page.has_more) {
|
||||
if (signal?.aborted) throw new DOMException('读取已取消', 'AbortError')
|
||||
const cursor = page.next_cursor
|
||||
@@ -358,6 +387,7 @@ export async function fetchAllQARecords(
|
||||
}
|
||||
page = mergeQAPages(page, next)
|
||||
onProgress?.(ids.size, total)
|
||||
onPage?.(page)
|
||||
}
|
||||
if (ids.size !== total) throw new Error('全量读取数量不完整,请重试,未将部分记录当作全部结果')
|
||||
return page
|
||||
|
||||
Reference in New Issue
Block a user