diff --git a/src/library/track.rs b/src/library/track.rs index 867ac85..6c45bf5 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -198,17 +198,8 @@ 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 { - let latest_events = Event::get_latest_events_of(u).await; - let mut ids = HashSet::new(); - - for event in latest_events { - if !ids.contains(&event.track) { - ids.insert(event.track.clone()); - } - } - - sqlx::query_as("SELECT * FROM track WHERE id = ANY($1)") - .bind(ids.into_iter().collect::>()) + sqlx::query_as("SELECT DISTINCT t.* FROM track t JOIN events e ON t.id = e.track WHERE e.user = $1 ORDER BY e.time DESC") + .bind(&u.username) .fetch_all(get_pg!()) .await .unwrap()