fix
This commit is contained in:
parent
334790da70
commit
0554040341
1 changed files with 2 additions and 11 deletions
|
@ -198,17 +198,8 @@ impl Track {
|
||||||
///
|
///
|
||||||
/// A vector of `Track` objects representing the latest tracks for the given user.
|
/// A vector of `Track` objects representing the latest tracks for the given user.
|
||||||
pub async fn get_latest_of_user(u: &User) -> Vec<Self> {
|
pub async fn get_latest_of_user(u: &User) -> Vec<Self> {
|
||||||
let latest_events = Event::get_latest_events_of(u).await;
|
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")
|
||||||
let mut ids = HashSet::new();
|
.bind(&u.username)
|
||||||
|
|
||||||
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::<Vec<_>>())
|
|
||||||
.fetch_all(get_pg!())
|
.fetch_all(get_pg!())
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
Loading…
Reference in a new issue