Run homepage compress in parallel
This commit is contained in:
@@ -30,6 +30,7 @@ const dragActive = ref(false)
|
|||||||
|
|
||||||
const items = ref<UploadItem[]>([])
|
const items = ref<UploadItem[]>([])
|
||||||
const busy = computed(() => items.value.some((x) => x.status === 'compressing'))
|
const busy = computed(() => items.value.some((x) => x.status === 'compressing'))
|
||||||
|
const maxParallel = 3
|
||||||
|
|
||||||
const alert = ref<{ type: 'info' | 'success' | 'error'; message: string } | null>(null)
|
const alert = ref<{ type: 'info' | 'success' | 'error'; message: string } | null>(null)
|
||||||
const sendingVerification = ref(false)
|
const sendingVerification = ref(false)
|
||||||
@@ -133,10 +134,25 @@ async function runOne(item: UploadItem) {
|
|||||||
|
|
||||||
async function runAll() {
|
async function runAll() {
|
||||||
alert.value = null
|
alert.value = null
|
||||||
for (const item of items.value) {
|
const queue = items.value.filter((item) => item.status !== 'done')
|
||||||
if (item.status === 'done') continue
|
if (queue.length === 0) return
|
||||||
|
|
||||||
|
let cursor = 0
|
||||||
|
const worker = async () => {
|
||||||
|
while (cursor < queue.length) {
|
||||||
|
const item = queue[cursor]
|
||||||
|
cursor += 1
|
||||||
|
if (item) {
|
||||||
await runOne(item)
|
await runOne(item)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const workers = Array.from(
|
||||||
|
{ length: Math.min(maxParallel, queue.length) },
|
||||||
|
() => worker(),
|
||||||
|
)
|
||||||
|
await Promise.all(workers)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function download(item: UploadItem) {
|
async function download(item: UploadItem) {
|
||||||
|
|||||||
Reference in New Issue
Block a user