@@ -22,7 +22,7 @@ use semver::Version;
2222use serde:: Serialize ;
2323use sqlx:: {
2424 types:: chrono:: { DateTime , Utc } ,
25- PgConnection
25+ PgConnection ,
2626} ;
2727use std:: { collections:: HashMap , str:: FromStr } ;
2828
@@ -196,11 +196,11 @@ impl Mod {
196196 } ;
197197
198198 let order = match query. sort {
199- IndexSortType :: Downloads => "m .download_count DESC" ,
200- IndexSortType :: RecentlyUpdated => "m .updated_at DESC" ,
201- IndexSortType :: RecentlyPublished => "m .created_at DESC" ,
202- IndexSortType :: Name => "mv .name ASC" ,
203- IndexSortType :: NameReverse => "mv .name DESC" ,
199+ IndexSortType :: Downloads => "q .download_count DESC" ,
200+ IndexSortType :: RecentlyUpdated => "q .updated_at DESC" ,
201+ IndexSortType :: RecentlyPublished => "q .created_at DESC" ,
202+ IndexSortType :: Name => "q .name ASC" ,
203+ IndexSortType :: NameReverse => "q .name DESC" ,
204204 } ;
205205
206206 let geode = query
@@ -270,15 +270,20 @@ impl Mod {
270270 "# ;
271271
272272 let records: Vec < ModRecord > = sqlx:: query_as ( & format ! (
273- "SELECT
274- m.id, m.repository, m.about, m.changelog,
275- m.download_count, m.featured, m.created_at, m.updated_at
276- FROM mods m
277- {}
278- GROUP BY m.id
273+ "SELECT q.id, q.repository, q.about, q.changelog,
274+ q.download_count, q.featured, q.created_at, q.updated_at
275+ FROM (
276+ SELECT m.id, mv.name, m.repository, m.about, m.changelog,
277+ m.download_count, m.featured, m.created_at, m.updated_at,
278+ ROW_NUMBER() OVER (PARTITION BY m.id ORDER BY mv.id DESC) rn
279+ FROM mods m
280+ {}
281+ ) q
282+ WHERE q.rn = 1
279283 ORDER BY {}
280284 LIMIT $11
281- OFFSET $12" ,
285+ OFFSET $12
286+ " ,
282287 joins_filters, order
283288 ) )
284289 . bind ( tags. as_ref ( ) )
0 commit comments