From 24a4f81c41548e7773b9e6bf64d6abb039099cf8 Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Sat, 20 Dec 2025 18:09:39 +0800 Subject: [PATCH] Run homepage compress in parallel --- frontend/src/pages/HomePage.vue | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/HomePage.vue b/frontend/src/pages/HomePage.vue index d7d0253..7688a67 100644 --- a/frontend/src/pages/HomePage.vue +++ b/frontend/src/pages/HomePage.vue @@ -30,6 +30,7 @@ const dragActive = ref(false) const items = ref([]) 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 sendingVerification = ref(false) @@ -133,10 +134,25 @@ async function runOne(item: UploadItem) { async function runAll() { alert.value = null - for (const item of items.value) { - if (item.status === 'done') continue - await runOne(item) + const queue = items.value.filter((item) => item.status !== 'done') + 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) + } + } } + + const workers = Array.from( + { length: Math.min(maxParallel, queue.length) }, + () => worker(), + ) + await Promise.all(workers) } async function download(item: UploadItem) {