perf(代码审查落地): 后端 A1-A8 与前端 C1-C8 加固,retention 清理补索引(V141)
A 组(backend-java): - A1 载荷引用计数不再无条件回落全表 COUNT - A2 结果行读取由 LIMIT 1 改整页 - A3 ziniao 索引缓存过期判断下推 SQL - A4 循环子任务认领改 CAS,失败一律抛 - A5 建单事务里不碰外部 IO - A6 连接池补网络层超时(connectTimeout/socketTimeout,env 可覆盖) - A7 日志留现场 + 异步落盘 - A8 其余:货源图片预取、结果工作簿装配等 - V141:三条 retention DELETE 的可用索引,其中 biz_price_track_loop_run 用 STORED 生成列承载 COALESCE 时间线(该表实测 881 行/17MB,COPY 秒级) C 组(frontend-vue):URL 取值走 safe-url、行号取值走 row-id、 交付视频任务状态抽成 delivery-video-task-state.ts,各补用例。
This commit is contained in:
@@ -143,14 +143,14 @@
|
||||
<div class="kv-section">结果文件</div>
|
||||
<div v-for="(url, index) in resultFiles(detailItem)" :key="url" class="kv-row">
|
||||
<span class="kv-key">文件 {{ index + 1 }}</span>
|
||||
<a class="kv-val link" :href="url" target="_blank" rel="noopener">{{ url }}</a>
|
||||
<a class="kv-val link" :href="safeHttpUrl(url)" target="_blank" rel="noopener">{{ url }}</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="detailItem.task_data?.file_url">
|
||||
<div class="kv-section">源文件</div>
|
||||
<div class="kv-row">
|
||||
<span class="kv-key">源文件</span>
|
||||
<a class="kv-val link" :href="detailItem.task_data.file_url" target="_blank" rel="noopener">{{ detailItem.task_data.file_url }}</a>
|
||||
<a class="kv-val link" :href="sourceFileHref(detailItem)" target="_blank" rel="noopener">{{ detailItem.task_data.file_url }}</a>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -159,7 +159,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import AmazonToolPageShell from '@/pages/amazon/components/AmazonToolPageShell.vue'
|
||||
import {
|
||||
@@ -167,6 +167,9 @@ import {
|
||||
type VariantTaskListItem,
|
||||
} from '@/shared/bridges/pywebview'
|
||||
import { saveUrlWithProgress } from '@/shared/utils/download-progress'
|
||||
import { safeHttpUrl } from '@/shared/utils/safe-url'
|
||||
import { createCategorizedTimers } from '@/shared/utils/categorized-timers'
|
||||
import { useHistoryPolling } from '@/shared/composables/useHistoryPolling'
|
||||
import { taskStatusClass, taskStatusText, type TaskStatusOptions } from '@/shared/utils/task-status-text'
|
||||
|
||||
/** 本地任务记录:桥接返回的列表项 + 前端维护字段 */
|
||||
@@ -252,7 +255,6 @@ function statusClass(status?: number | string) {
|
||||
}
|
||||
|
||||
let autoTimer: number | null = null
|
||||
let refreshTimer: number | null = null
|
||||
// 导出轮询用独立计时器:此前与自动刷新共用 autoTimer,两条链互相覆盖,必有一条无法被 cleanup 清掉
|
||||
let exportTimer: number | null = null
|
||||
// 组件已卸载标记:轮询链的异步回调在卸载后仍会续链(切页后继续打接口)
|
||||
@@ -302,6 +304,11 @@ function resultFiles(item?: VariantEntry) {
|
||||
return toArray(item?.file_url)
|
||||
}
|
||||
|
||||
/** 源文件链接:task_data 是客户端原样透传的开放对象,渲染前必须过 http(s) 白名单 */
|
||||
function sourceFileHref(item?: VariantEntry) {
|
||||
return safeHttpUrl(item?.task_data?.file_url)
|
||||
}
|
||||
|
||||
function hasResultFiles(item: VariantTaskListItem) {
|
||||
const resType = Number(item.res_type)
|
||||
return (resType === 1 || String(item.res_type) === '1') && resultFiles(item).length > 0
|
||||
@@ -659,49 +666,70 @@ function showDetail(item: VariantTaskListItem) {
|
||||
detailVisible.value = true
|
||||
}
|
||||
|
||||
const timers = createCategorizedTimers('variant')
|
||||
|
||||
/** 列表里是否还有排队/执行中的任务(没有就不该再定时打接口) */
|
||||
const hasActiveTask = computed(() => currentTasks.value.some((item) => isBusy(item.status)))
|
||||
|
||||
function clearAutoRefresh() {
|
||||
if (!autoTimer) return
|
||||
window.clearTimeout(autoTimer)
|
||||
autoTimer = null
|
||||
}
|
||||
|
||||
function scheduleAutoRefresh() {
|
||||
if (autoTimer) {
|
||||
window.clearTimeout(autoTimer)
|
||||
autoTimer = null
|
||||
}
|
||||
clearAutoRefresh()
|
||||
autoTimer = window.setTimeout(async () => {
|
||||
if (disposed) {
|
||||
return
|
||||
}
|
||||
await loadTasks(currentPage.value || 1)
|
||||
// 卸载后不得再续链:异步回调返回时组件可能已销毁,续链会持续打接口
|
||||
if (!disposed && currentTasks.value.some((item) => isBusy(item.status))) {
|
||||
if (!disposed && hasActiveTask.value) {
|
||||
scheduleAutoRefresh()
|
||||
}
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
void loadTasks(1)
|
||||
refreshTimer = window.setInterval(() => {
|
||||
void loadTasks(currentPage.value || 1)
|
||||
}, 60 * 1000)
|
||||
}
|
||||
/**
|
||||
* 历史列表轮询(审查 C4):此前是无条件的 60 秒 setInterval(既无 shouldPoll 也无可见性判断),
|
||||
* 页面挂着不动也一直打 /batch/list。现在只在「有活跃任务」时按同样的 60 秒节奏刷新,空闲即停;
|
||||
* 定时器统一登记进 categorized-timers,卸载时由 clearScope 兜底清理。
|
||||
*/
|
||||
const historyPolling = useHistoryPolling({
|
||||
timers,
|
||||
isDisposed: () => disposed,
|
||||
shouldPoll: () => hasActiveTask.value,
|
||||
refresh: () => loadTasks(currentPage.value || 1),
|
||||
// 保持原 60 秒节奏,只是加上了「有活跃任务」的门槛
|
||||
intervalMs: () => 60 * 1000,
|
||||
})
|
||||
|
||||
// 活跃任务出现 → 起 3 秒快刷链 + 60 秒列表轮询;全部落定 → 两条链都停
|
||||
watch(hasActiveTask, (active) => {
|
||||
if (active) {
|
||||
scheduleAutoRefresh()
|
||||
historyPolling.start()
|
||||
} else {
|
||||
clearAutoRefresh()
|
||||
historyPolling.stop()
|
||||
}
|
||||
})
|
||||
|
||||
function cleanup() {
|
||||
disposed = true
|
||||
if (autoTimer) {
|
||||
window.clearTimeout(autoTimer)
|
||||
autoTimer = null
|
||||
}
|
||||
clearAutoRefresh()
|
||||
if (exportTimer) {
|
||||
window.clearTimeout(exportTimer)
|
||||
exportTimer = null
|
||||
}
|
||||
if (refreshTimer) {
|
||||
window.clearInterval(refreshTimer)
|
||||
refreshTimer = null
|
||||
}
|
||||
historyPolling.stop()
|
||||
timers.clearScope()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startPolling()
|
||||
scheduleAutoRefresh()
|
||||
// 首发只发一次:此前 startPolling() 的立即 loadTasks(1) 与 scheduleAutoRefresh() 各打一遍同一页
|
||||
void loadTasks(1)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
Reference in New Issue
Block a user