Run homepage compress in parallel

This commit is contained in:
2025-12-20 18:09:39 +08:00
parent d17b9d2136
commit 24a4f81c41

View File

@@ -30,6 +30,7 @@ const dragActive = ref(false)
const items = ref<UploadItem[]>([])
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
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) {