Browse Source

And for playlist YouTube importing too of course

Kristian Vos 4 years ago
parent
commit
9f6ddfac28
1 changed files with 33 additions and 30 deletions
  1. 33 30
      backend/logic/actions/playlists.js

+ 33 - 30
backend/logic/actions/playlists.js

@@ -624,42 +624,45 @@ export default {
 					});
 				},
 				(songIds, next) => {
-					let processed = 0;
 					let successful = 0;
 					let failed = 0;
 					let alreadyInPlaylist = 0;
 
 					if (songIds.length === 0) next();
 
-					songIds.forEach(songId => {
-						IOModule.runJob(
-							"RUN_ACTION2",
-							{
-								session,
-								namespace: "playlists",
-								action: "addSongToPlaylist",
-								args: [true, songId, playlistId]
-							},
-							this
-						)
-							.then(res => {
-								if (res.status === "success") {
-									successful += 1;
-									addedSongs.push(songId);
-								} else failed += 1;
-								if (res.message === "That song is already in the playlist") alreadyInPlaylist += 1;
-							})
-							.catch(() => {
-								failed += 1;
-							})
-							.finally(() => {
-								processed += 1;
-								if (processed === songIds.length) {
-									addSongsStats = { successful, failed, alreadyInPlaylist };
-									next(null);
-								}
-							});
-					});
+					async.eachLimit(
+						songIds,
+						1,
+						(songId, next) => {
+							IOModule.runJob(
+								"RUN_ACTION2",
+								{
+									session,
+									namespace: "playlists",
+									action: "addSongToPlaylist",
+									args: [true, songId, playlistId]
+								},
+								this
+							)
+								.then(res => {
+									if (res.status === "success") {
+										successful += 1;
+										addedSongs.push(songId);
+									} else failed += 1;
+									if (res.message === "That song is already in the playlist") alreadyInPlaylist += 1;
+								})
+								.catch(() => {
+									failed += 1;
+								})
+								.finally(() => {
+									next();
+								});
+						},
+						() => {
+							addSongsStats = { successful, failed, alreadyInPlaylist };
+							next(null);
+						}
+					);
 				},
 
 				next => {