Forráskód Böngészése

feat: Activate parallel downloads for 3-4x faster performance

Problem:
- DownloadManager already supported parallel downloads (max 4 concurrent)
- But app.js was downloading videos sequentially in a for loop
- User had to wait for each video to complete before next started
- 10 videos took ~10 minutes instead of ~3 minutes

Solution:
- Changed from sequential for loop with await to Promise.all()
- All download requests now fire simultaneously
- DownloadManager handles concurrency limits (max 4 concurrent)
- Videos download in parallel batches

Implementation:
- Replaced: for (video) { await downloadVideo() }
- With: Promise.all(videos.map(video => downloadVideo()))
- Added console logging for parallel download start
- Updated status message: "Starting parallel download..."

Performance:
- Before: Sequential (1 video at a time)
- After: Parallel (up to 4 videos simultaneously)
- Expected: 3-4x faster for multiple videos
- 10 videos: ~10 min → ~3 min

User tested and confirmed: "fantastic...again.. well done"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
jopa79 3 hónapja
szülő
commit
a19b8f05cb
1 módosított fájl, 16 hozzáadás és 9 törlés
  1. 16 9
      scripts/app.js

+ 16 - 9
scripts/app.js

@@ -571,18 +571,18 @@ class GrabZillaApp {
         }
 
         this.state.updateUI({ isDownloading: true });
-        this.updateStatusMessage(`Starting download of ${videos.length} video(s)...`);
+        this.updateStatusMessage(`Starting parallel download of ${videos.length} video(s)...`);
 
         // Set up download progress listener
         window.IPCManager.onDownloadProgress('app', (progressData) => {
             this.handleDownloadProgress(progressData);
         });
 
-        // Download videos sequentially
-        let successCount = 0;
-        let failedCount = 0;
+        // PARALLEL DOWNLOADS: Start all downloads simultaneously
+        // The DownloadManager will handle concurrency limits automatically
+        console.log(`Starting ${videos.length} downloads in parallel...`);
 
-        for (const video of videos) {
+        const downloadPromises = videos.map(async (video) => {
             try {
                 // Update video status to downloading
                 this.state.updateVideo(video.id, { status: 'downloading', progress: 0 });
@@ -602,19 +602,19 @@ class GrabZillaApp {
                         progress: 100,
                         filename: result.filename
                     });
-                    successCount++;
 
                     // Show notification for successful download
                     this.showDownloadNotification(video, 'success');
+                    return { success: true, video };
                 } else {
                     this.state.updateVideo(video.id, {
                         status: 'error',
                         error: result.error || 'Download failed'
                     });
-                    failedCount++;
 
                     // Show notification for failed download
                     this.showDownloadNotification(video, 'error', result.error);
+                    return { success: false, video, error: result.error };
                 }
 
             } catch (error) {
@@ -623,9 +623,16 @@ class GrabZillaApp {
                     status: 'error',
                     error: error.message
                 });
-                failedCount++;
+                return { success: false, video, error: error.message };
             }
-        }
+        });
+
+        // Wait for all downloads to complete
+        const results = await Promise.all(downloadPromises);
+
+        // Count successes and failures
+        const successCount = results.filter(r => r.success).length;
+        const failedCount = results.filter(r => !r.success).length;
 
         // Clean up progress listener
         window.IPCManager.removeDownloadProgressListener('app');