feat: web resource分批请求
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
if (isFetchingUrls) {
|
||||||
|
pendingUrlList = list
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isFetchingUrls = true
|
||||||
|
if (urlList.value.length < 1) {
|
||||||
urlLoading.value = true
|
urlLoading.value = true
|
||||||
const res = await fetchUrlTitle(newUrls)
|
}
|
||||||
|
for (let i = 0; i < newUrls.length; i += BATCH_SIZE) {
|
||||||
|
const batch = newUrls.slice(i, i + BATCH_SIZE)
|
||||||
|
await fetchBatch(batch)
|
||||||
urlLoading.value = false
|
urlLoading.value = false
|
||||||
newUrls.forEach((url) => fetchedUrlSet.value.add(url))
|
}
|
||||||
urlList.value = [...urlList.value, ...res]
|
isFetchingUrls = false
|
||||||
|
|
||||||
|
if (pendingUrlList) {
|
||||||
|
const next = pendingUrlList
|
||||||
|
pendingUrlList = null
|
||||||
|
setUrls(next)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// watch(
|
// watch(
|
||||||
// () => sessionId.value,
|
// () => sessionId.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user