Fixed SQL error when reading large playlist
This commit is contained in:
parent
0f0fce66ce
commit
9d0ecc5531
1 changed files with 11 additions and 8 deletions
|
@ -13,6 +13,8 @@ use index::Song;
|
||||||
use vfs::VFSSource;
|
use vfs::VFSSource;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
|
||||||
|
const PLAYLIST_CHUNK: usize = 500;
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
#[table_name="playlists"]
|
#[table_name="playlists"]
|
||||||
struct NewPlaylist {
|
struct NewPlaylist {
|
||||||
|
@ -151,6 +153,7 @@ fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<Song
|
||||||
let song_paths: Vec<String>;
|
let song_paths: Vec<String>;
|
||||||
let unique_songs: Vec<Song>;
|
let unique_songs: Vec<Song>;
|
||||||
let vfs = db.get_vfs()?;
|
let vfs = db.get_vfs()?;
|
||||||
|
let mut songs_map: HashMap<String, Song> = HashMap::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let connection = db.get_connection();
|
let connection = db.get_connection();
|
||||||
|
@ -184,17 +187,17 @@ fn read_playlist<T>(playlist_name: &str, owner: &str, db: &T) -> Result<Vec<Song
|
||||||
// Find Song objects at the relevant paths
|
// Find Song objects at the relevant paths
|
||||||
{
|
{
|
||||||
use self::songs::dsl::*;
|
use self::songs::dsl::*;
|
||||||
unique_songs = songs
|
for chunk in song_paths[..].chunks(PLAYLIST_CHUNK) {
|
||||||
.filter(path.eq_any(&song_paths))
|
let unique_songs: Vec<Song> = songs
|
||||||
.get_results(connection.deref())?;
|
.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
|
// Build playlist
|
||||||
let mut playlist_songs = Vec::new();
|
let mut playlist_songs = Vec::new();
|
||||||
for path in &song_paths {
|
for path in &song_paths {
|
||||||
|
|
Loading…
Add table
Reference in a new issue