diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-25 18:09:58 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-25 18:09:58 +0200 |
commit | 095ad981db8e11fcda0207eaaad92b80ec9a990d (patch) | |
tree | c2018b9c6cf4f0ae768c525cbac55676e7bbdc60 /planetwars-server/src/db | |
parent | 55c76db7b60ae142a1d224e4d485771d7be2b51f (diff) | |
download | planetwars.dev-095ad981db8e11fcda0207eaaad92b80ec9a990d.tar.xz planetwars.dev-095ad981db8e11fcda0207eaaad92b80ec9a990d.zip |
fix ordering in list_matches
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r-- | planetwars-server/src/db/match_queries.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/planetwars-server/src/db/match_queries.rs b/planetwars-server/src/db/match_queries.rs index 999802f..f9f8140 100644 --- a/planetwars-server/src/db/match_queries.rs +++ b/planetwars-server/src/db/match_queries.rs @@ -40,6 +40,7 @@ impl QueryFragment<Pg> for ListBotMatches { out.push_sql(") main_player ON matches.id = main_player.match_id"); + // TODO: this won't work properly for matches with > 2 players if let Some(opponent_id) = self.opponent_id.as_ref() { out.push_sql(" JOIN ("); out.push_sql(concat!( @@ -70,11 +71,14 @@ impl QueryFragment<Pg> for ListBotMatches { if let Some(before) = self.before.as_ref() { out.push_sql(" AND matches.created_at < "); out.push_bind_param::<Timestamp, _>(before)?; - out.push_sql(" ORDER BY matches.created_at DESC"); } else if let Some(after) = self.after.as_ref() { out.push_sql(" AND matches.created_at > "); out.push_bind_param::<Timestamp, _>(after)?; - out.push_sql(" ORDER BY matches.created_at ASC"); + } + if self.after.is_some() { + out.push_sql(" ORDER BY matches.created_at ASC") + } else { + out.push_sql(" ORDER BY matches.created_at DESC") } out.push_sql(" LIMIT "); out.push_bind_param::<BigInt, _>(&self.amount)?; |