Ver Fonte

fix: bulk add artists/genres/tags had a few issues

Kristian Vos há 2 anos atrás
pai
commit
33a92f9243
1 ficheiros alterados com 3 adições e 33 exclusões
  1. 3 33
      backend/logic/actions/songs.js

+ 3 - 33
backend/logic/actions/songs.js

@@ -1892,17 +1892,7 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
-						songModel.updateMany(
-							{ _id: { $in: songsFound } },
-							{ $pullAll: { genres } },
-							{ runValidators: true },
-							err => {
-								if (err) {
-									next(err);
-								}
-							}
-						);
-						query.$push = { genres: { $each: genres } };
+						query.$addToSet = { genres: { $each: genres } };
 					} else if (method === "remove") {
 						query.$pullAll = { genres };
 					} else if (method === "replace") {
@@ -2000,17 +1990,7 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
-						songModel.updateMany(
-							{ _id: { $in: songsFound } },
-							{ $pullAll: { artists } },
-							{ runValidators: true },
-							err => {
-								if (err) {
-									next(err);
-								}
-							}
-						);
-						query.$push = { artists: { $each: artists } };
+						query.$addToSet = { artists: { $each: artists } };
 					} else if (method === "remove") {
 						query.$pullAll = { artists };
 					} else if (method === "replace") {
@@ -2108,17 +2088,7 @@ export default {
 				(songsFound, next) => {
 					const query = {};
 					if (method === "add") {
-						songModel.updateMany(
-							{ _id: { $in: songsFound } },
-							{ $pullAll: { tags } },
-							{ runValidators: true },
-							err => {
-								if (err) {
-									next(err);
-								}
-							}
-						);
-						query.$push = { tags: { $each: tags } };
+						query.$addToSet = { tags: { $each: tags } };
 					} else if (method === "remove") {
 						query.$pullAll = { tags };
 					} else if (method === "replace") {