From 17c8ede5e968786f55e16c16d64febbce5b87200 Mon Sep 17 00:00:00 2001 From: Suzu008 Date: Tue, 24 Mar 2026 08:44:39 +0800 Subject: [PATCH] perf: parallelize video decryption using Promise.allSettled --- ts/cryptioSaveVideo.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/ts/cryptioSaveVideo.ts b/ts/cryptioSaveVideo.ts index 1e59ba4..2f34884 100644 --- a/ts/cryptioSaveVideo.ts +++ b/ts/cryptioSaveVideo.ts @@ -176,26 +176,29 @@ app.registerExtension({ this.removeWidget(widget); } - // Create new widgets for each video + // Create widgets and decrypt videos in parallel + const updatePromises: Promise[] = []; for (let i = 0; i < message.cryptio_images.length; i++) { const videoInfo = message.cryptio_images[i]; if (videoInfo.filename && videoInfo.filename.endsWith(".encrypted")) { const videoName = `video_${i}`; const widget = createVideoWidget(this, videoName, videoInfo); - try { - const videoUrl = await updateVideoWidget(widget, videoInfo); - - // If auto-download is enabled - if (autoDownload) { - downloadDecryptedVideo(videoUrl, videoInfo.filename); - console.log(`Auto-downloaded decrypted video: ${videoInfo.filename.replace(/\.encrypted$/, "")}`); - } - } catch (error) { - console.error("Failed to load video:", error); - } + updatePromises.push( + updateVideoWidget(widget, videoInfo) + .then((videoUrl) => { + if (autoDownload) { + downloadDecryptedVideo(videoUrl, videoInfo.filename); + console.log(`Auto-downloaded decrypted video: ${videoInfo.filename.replace(/\.encrypted$/, "")}`); + } + }) + .catch((error) => { + console.error("Failed to load video:", error); + }) + ); } } + await Promise.allSettled(updatePromises); } };