diff --git a/src/library/track.rs b/src/library/track.rs index d28b41c..2e51627 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -198,23 +198,21 @@ impl Track { /// /// A vector of `Track` objects representing the latest tracks for the given user. pub async fn get_latest_of_user(u: &User) -> Vec { - // todo : weird - let res: Vec<(uuid::Uuid, String, String, chrono::DateTime, Option, Option, Option, chrono::DateTime)> = sqlx::query_as("SELECT DISTINCT(t.*), e.time FROM track t JOIN events e ON t.id = e.track WHERE e.user = $1 ORDER BY e.time DESC LIMIT 300") + let ids: Vec<(uuid::Uuid,)> = sqlx::query_as( + "SELECT DISTINCT(track) FROM events WHERE \"user\" = $1 ORDER BY time DESC LIMIT 300", + ) .bind(&u.username) - .fetch_all(get_pg!()) - .await - .unwrap(); - res.into_iter() - .map(|x| Self { - id: x.0, - path: x.1, - title: x.2, - date_added: x.3, - album: x.4, - artist: x.5, - meta: x.6, - }) - .collect() + .fetch_all(get_pg!()) + .await + .unwrap(); + + let mut tracks: Vec<_> = Vec::with_capacity(300); + + for track in ids { + tracks.push(Track::get(&track.0).await.unwrap()); + } + + tracks } /// Transcodes audio to OPUS format with the specified bitrate.