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

Method insert_songs_by_ref

src-tauri/database/src/database.rs:208–292  ·  view source on GitHub ↗
(&self, songs: &mut [Song])

Source from the content-addressed store, hash-verified

206 }
207
208 pub fn insert_songs_by_ref(&self, songs: &mut [Song]) -> Result<()> {
209 let mut conn = self.pool.get().unwrap();
210 trace!("Inserting songs");
211 for song in songs {
212 if song.song._id.is_none() {
213 song.song._id = Some(Uuid::new_v4().to_string());
214 }
215
216 let changed = insert_into(allsongs)
217 .values(&song.song)
218 .on_conflict(song_path)
219 .do_update()
220 .set(&song.song)
221 .execute(&mut conn)?;
222
223 if changed == 0 {
224 continue;
225 }
226
227 if let Some(_album) = &mut song.album {
228 let album_id_ = self
229 .get_albums(
230 QueryableAlbum::search_by_term(_album.album_name.clone()),
231 false,
232 &mut conn,
233 )?
234 .first()
235 .map(|v| v.album_id.clone().unwrap())
236 .unwrap_or_else(|| self.insert_album(&mut conn, _album).unwrap());
237
238 AlbumBridge::insert_value(album_id_.clone(), song.song._id.clone().unwrap())
239 .insert_into(album_bridge)
240 .on_conflict_do_nothing()
241 .execute(&mut conn)?;
242
243 _album.album_id = Some(album_id_);
244 }
245
246 if let Some(_artists) = &mut song.artists {
247 for mut _artist in _artists {
248 let artist_id_ = self
249 .get_artists(
250 QueryableArtist::search_by_term(_artist.artist_name.clone()),
251 false,
252 &mut conn,
253 )?
254 .first()
255 .map(|v| v.artist_id.clone().unwrap())
256 .unwrap_or_else(|| self.insert_artist(&mut conn, _artist).unwrap());
257
258 ArtistBridge::insert_value(artist_id_.clone(), song.song._id.clone().unwrap())
259 .insert_into(artist_bridge)
260 .on_conflict_do_nothing()
261 .execute(&mut conn)?;
262
263 _artist.artist_id = Some(artist_id_);
264 }
265 }

Callers 2

insert_songsMethod · 0.80
add_to_playlistMethod · 0.80

Calls 9

getMethod · 0.80
setMethod · 0.80
get_albumsMethod · 0.80
cloneMethod · 0.80
insert_albumMethod · 0.80
get_artistsMethod · 0.80
insert_artistMethod · 0.80
get_genresMethod · 0.80
insert_genreMethod · 0.80

Tested by

no test coverage detected