feat: web resource分批请求

This commit is contained in:
2026-06-04 16:12:01 +08:00
parent 60323ad9bd
commit 6934f3e4fe

View File

@@ -210,15 +210,43 @@
const urlLoading = ref(false)
const fetchedUrlSet = ref<Set<string>>(new Set())
const BATCH_SIZE = 4
let isFetchingUrls = false
let pendingUrlList: string[] | null = null
const fetchBatch = async (batch: string[]) => {
const res = await fetchUrlTitle(batch)
batch.forEach((url) => fetchedUrlSet.value.add(url))
urlList.value = [...urlList.value, ...res]
}
const setUrls = async (list: string[]) => {
reportType.value = 'urls'
const newUrls = [...new Set(list.filter((url) => !fetchedUrlSet.value.has(url)))]
if (newUrls.length === 0) return
urlLoading.value = true
const res = await fetchUrlTitle(newUrls)
urlLoading.value = false
newUrls.forEach((url) => fetchedUrlSet.value.add(url))
urlList.value = [...urlList.value, ...res]
if (isFetchingUrls) {
pendingUrlList = list
return
}
isFetchingUrls = true
if (urlList.value.length < 1) {
urlLoading.value = true
}
for (let i = 0; i < newUrls.length; i += BATCH_SIZE) {
const batch = newUrls.slice(i, i + BATCH_SIZE)
await fetchBatch(batch)
urlLoading.value = false
}
isFetchingUrls = false
if (pendingUrlList) {
const next = pendingUrlList
pendingUrlList = null
setUrls(next)
}
}
// watch(
// () => sessionId.value,