Skip to content

Commit 04bf9e1

Browse files
authored
index: squash several more bugs (#19)
- remove freighter readme from toml so that more tools work - don't return duplicate versions from the list_all endpoint - fix error in test config.toml - fix broken search sorting - ensure people cant yank or attempt to pull crates that aren't actually in the registry
1 parent 4b7e50c commit 04bf9e1

File tree

7 files changed

+16
-6
lines changed

7 files changed

+16
-6
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[registries]
2-
freighter = { index = "sparse+https://127.0.0.1:3000/index/" }
2+
freighter = { index = "sparse+http://127.0.0.1:3000/index/" }

freighter-index/sql/confirm-existence.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ from crates
33
join crate_versions cv on crates.id = cv.crate
44
where crates.name = $1
55
and cv.version = $2
6+
and crates.registry = ''

freighter-index/sql/list.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ select c.name,
55
c.repository,
66
c.created_at,
77
c.updated_at,
8-
array_agg(cv.version) as versions,
8+
array_agg(distinct cv.version) as versions,
99
array_agg(distinct cat.name) filter ( where cat.name is not null ) as categories,
1010
array_agg(distinct k.name) filter ( where k.name is not null ) as keywords
1111
from crates c

freighter-index/sql/search.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
select crates.name,
22
crates.description,
3-
array_agg(cv.version) as versions,
4-
count(dependency)
3+
array_agg(distinct cv.version) as versions,
4+
count(distinct concat(d.dependent, crates.id))
55
from crates
66
join crate_versions cv on crates.id = cv.crate
77
left join dependencies d on crates.id = d.dependency

freighter-index/sql/set-yank.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ update crate_versions cv
22
set yanked = $3
33
from crates c
44
where c.name = $1
5+
and c.registry = ''
56
and cv.crate = c.id
67
and cv.version = $2
78
returning c.name, cv.version, cv.yanked;

freighter-index/src/postgres_client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use futures_util::StreamExt;
1111
use metrics::histogram;
1212
use postgres_types::ToSql;
1313
use semver::{Version, VersionReq};
14+
use std::cmp::Ordering;
1415
use std::collections::HashMap;
1516
use std::future::Future;
1617
use std::pin::Pin;
@@ -219,7 +220,15 @@ impl IndexProvider for PgIndexProvider {
219220

220221
// we can't scale the DB as easily as we can this server, so let's sort in here
221222
// warning: may be expensive!
222-
rows.sort_unstable_by_key(|r| (r.get::<_, i64>("count"), r.get::<_, String>("name")));
223+
//
224+
// sort first by version in descending order, then by name alphabetically
225+
rows.sort_unstable_by(|a, b| {
226+
match a.get::<_, i64>("count").cmp(&b.get::<_, i64>("count")) {
227+
Ordering::Less => Ordering::Greater,
228+
Ordering::Equal => a.get::<_, String>("name").cmp(&b.get::<_, String>("name")),
229+
Ordering::Greater => Ordering::Less,
230+
}
231+
});
223232

224233
let total = rows.len();
225234

freighter/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repository = "https://github.com/cloudflare/freighter"
99
description = "Crate index traits and implementations for the freighter registry"
1010
categories = ["asynchronous", "authentication"]
1111
keywords = ["registries", "freighter"]
12-
readme = "../README.md"
1312

1413
[dependencies]
1514
freighter-auth = { workspace = true, features = ["pg-backend"] }

0 commit comments

Comments
 (0)