@@ -34,7 +34,7 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
3434 releases.id IS NULL
3535 )
3636 ) AS inp
37- ORDER BY name, version "# ,
37+ ORDER BY name"# ,
3838 config. build_attempts as i32 ,
3939 )
4040 . fetch_all ( conn)
@@ -43,13 +43,15 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
4343 let mut crates = Crates :: new ( ) ;
4444
4545 for ( crate_name, release_rows) in & rows. iter ( ) . chunk_by ( |row| row. name . clone ( ) ) {
46- let releases: Releases = release_rows
46+ let mut releases: Releases = release_rows
4747 . map ( |row| Release {
4848 version : row. version . clone ( ) ,
4949 yanked : row. yanked ,
5050 } )
5151 . collect ( ) ;
5252
53+ releases. sort_by ( |lhs, rhs| lhs. version . cmp ( & rhs. version ) ) ;
54+
5355 crates. push ( Crate {
5456 name : crate_name,
5557 releases,
@@ -63,6 +65,7 @@ pub(super) async fn load(conn: &mut sqlx::PgConnection, config: &Config) -> Resu
6365mod tests {
6466 use super :: * ;
6567 use crate :: test:: { V1 , V2 , V3 , async_wrapper} ;
68+ use pretty_assertions:: assert_eq;
6669
6770 #[ test]
6871 fn test_load ( ) {
@@ -84,6 +87,35 @@ mod tests {
8487 . create ( )
8588 . await ?;
8689
90+ // these two releases are there to ensure we sort correctly.
91+ // In the past, we sorted the version (from the crates index & our database)
92+ // as string, which lead to "0.10.3" coming before "0.9.3".
93+ // When both sides are sorted the same way, this is fine and doesn't break the
94+ // consistency check.
95+ // But after migrating everything to using `semver::Version`, the sorting changed
96+ // on the index-side, while we still sorted by string on the database side.
97+ //
98+ // Since I still run the consistency check manually, every now and then, this wasn't
99+ // an issue, because I saw the odd huge difference.
100+ //
101+ // The solution is to sort both sides semver correctly.
102+ const V0_9_3 : Version = Version :: new ( 0 , 9 , 3 ) ;
103+ const V0_10_3 : Version = Version :: new ( 0 , 10 , 3 ) ;
104+ env. fake_release ( )
105+ . await
106+ . name ( "krate" )
107+ . version ( V0_9_3 )
108+ . yanked ( false )
109+ . create ( )
110+ . await ?;
111+ env. fake_release ( )
112+ . await
113+ . name ( "krate" )
114+ . version ( V0_10_3 )
115+ . yanked ( false )
116+ . create ( )
117+ . await ?;
118+
87119 let mut conn = env. async_db ( ) . async_conn ( ) . await ;
88120 let result = load ( & mut conn, env. config ( ) ) . await ?;
89121
@@ -93,6 +125,14 @@ mod tests {
93125 Crate {
94126 name: "krate" . into( ) ,
95127 releases: vec![
128+ Release {
129+ version: V0_9_3 ,
130+ yanked: Some ( false ) ,
131+ } ,
132+ Release {
133+ version: V0_10_3 ,
134+ yanked: Some ( false ) ,
135+ } ,
96136 Release {
97137 version: V2 ,
98138 yanked: Some ( false ) ,
0 commit comments