Skip to content

Commit 325738f

Browse files
committed
fix huge diff in consistency check due to different sorting
1 parent 52bb2be commit 325738f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.sqlx/query-f0bdee589c06dea8b71c5dd09cf8d3a4ebef2018ccefb61af8ed2dde44148ccc.json renamed to .sqlx/query-c8b2cc25bc619c4631709515e9b04271d5ad5901b6a9e292a256bd405b76e769.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/consistency/db.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6365
mod 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

Comments
 (0)