MCPcopy Create free account
hub / github.com/Moosync/Moosync / add_to_playlist

Method add_to_playlist

src-tauri/database/src/database.rs:924–957  ·  view source on GitHub ↗
(&self, id: String, mut songs: Vec<Song>)

Source from the content-addressed store, hash-verified

922
923 #[tracing::instrument(level = "debug", skip(self))]
924 pub fn add_to_playlist(&self, id: String, mut songs: Vec<Song>) -> Result<()> {
925 trace!("Adding to playlist");
926 songs.iter_mut().for_each(|v| {
927 v.song.show_in_library = Some(false);
928 });
929 let res = self.insert_songs_by_ref(songs.as_mut_slice());
930 if let Err(e) = res {
931 // Lets hope it only fails due to unique value constrains
932 tracing::warn!(
933 "Failed to insert songs in DB, maybe they already exist: {:?}",
934 e
935 );
936 }
937
938 self.pool
939 .get()
940 .unwrap()
941 .transaction::<(), MoosyncError, _>(|conn| {
942 for s in songs {
943 if let Err(e) = insert_into(playlist_bridge)
944 .values((
945 schema::playlist_bridge::playlist.eq(id.clone()),
946 schema::playlist_bridge::song.eq(s.song._id.clone()),
947 ))
948 .execute(conn)
949 {
950 warn!("Failed to add {:?} to playlist: {:?}", s, e);
951 }
952 }
953 Ok(())
954 })?;
955 info!("Added to playlist");
956 Ok(())
957 }
958
959 #[tracing::instrument(level = "debug", skip(self))]
960 pub fn remove_from_playlist(&self, id: String, songs: Vec<String>) -> Result<()> {

Callers 1

test_playlist_operationsFunction · 0.45

Calls 4

insert_songs_by_refMethod · 0.80
getMethod · 0.80
cloneMethod · 0.80
eqMethod · 0.45

Tested by 1

test_playlist_operationsFunction · 0.36