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 urlLoading = ref(false)
const fetchedUrlSet = ref<Set<string>>(new Set()) 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[]) => { const setUrls = async (list: string[]) => {
reportType.value = 'urls' reportType.value = 'urls'
const newUrls = [...new Set(list.filter((url) => !fetchedUrlSet.value.has(url)))] const newUrls = [...new Set(list.filter((url) => !fetchedUrlSet.value.has(url)))]
if (newUrls.length === 0) return if (newUrls.length === 0) return
urlLoading.value = true
const res = await fetchUrlTitle(newUrls) if (isFetchingUrls) {
urlLoading.value = false pendingUrlList = list
newUrls.forEach((url) => fetchedUrlSet.value.add(url)) return
urlList.value = [...urlList.value, ...res] }
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( // watch(
// () => sessionId.value, // () => sessionId.value,