diff --git a/src/playlist.rs b/src/playlist.rs index 7914b3b..6996b2d 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -13,6 +13,8 @@ use index::Song; use vfs::VFSSource; use errors::*; +const PLAYLIST_CHUNK: usize = 500; + #[derive(Insertable)] #[table_name="playlists"] struct NewPlaylist { @@ -151,6 +153,7 @@ fn read_playlist(playlist_name: &str, owner: &str, db: &T) -> Result; let unique_songs: Vec; let vfs = db.get_vfs()?; + let mut songs_map: HashMap = HashMap::new(); { let connection = db.get_connection(); @@ -184,17 +187,17 @@ fn read_playlist(playlist_name: &str, owner: &str, db: &T) -> Result = songs + .filter(path.eq_any(chunk)) + .get_results(connection.deref())?; + for playlist_song in &unique_songs { + songs_map.insert(playlist_song.path.clone(), playlist_song.clone()); + } + } } } - let mut songs_map: HashMap<&str, &Song> = HashMap::new(); - for playlist_song in &unique_songs { - songs_map.insert(&playlist_song.path, &playlist_song); - } - // Build playlist let mut playlist_songs = Vec::new(); for path in &song_paths {