From 9d0ecc55318c9ce970af72537a5644d0a91099a3 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Mon, 10 Jul 2017 22:33:00 -0700 Subject: [PATCH] Fixed SQL error when reading large playlist --- src/playlist.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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 {