Skip to content

Commit

Permalink
refactor: use sparse crates index
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed May 26, 2024
1 parent 85a077e commit 4ac7508
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 165 deletions.
118 changes: 4 additions & 114 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ badge = { path = "./libs/badge" }

anyhow = "1"
cadence = "1"
crates-index = { version = "2", default-features = false, features = ["git"] }
crates-index = "2"
derive_more = "0.99"
dotenvy = "0.15"
error_reporter = "1"
font-awesome-as-a-crate = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["std"] }
http = "1"
http-body-util = "0.1"
hyper = { version = "0.14.10", features = ["full"] }
error_reporter = "1"
indexmap = { version = "2", features = ["serde"] }
lru_time_cache = "0.11"
maud = "0.26"
once_cell = "1"
parking_lot = "0.12"
pulldown-cmark = "0.11"
relative-path = { version = "1", features = ["serde"] }
reqwest = { version = "0.12", features = ["json"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "http2", "rustls-tls", "gzip"] }
route-recognizer = "0.3"
rustsec = "0.29"
semver = { version = "1.0", features = ["serde"] }
Expand All @@ -41,9 +43,9 @@ toml = "0.8"
tracing = "0.1.30"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[target.'cfg(any())'.dependencies]
gix = { version = "0.63", default-features = false, features = ["blocking-http-transport-reqwest-rust-tls"] }

[build-dependencies]
grass = { version = "0.13", default-features = false }
sha-1 = "0.10"

[dev-dependencies]
static_assertions = "1"
4 changes: 2 additions & 2 deletions src/interactors/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use futures_util::FutureExt as _;
use hyper::service::Service;
use semver::{Version, VersionReq};
use serde::Deserialize;
use tokio::task::spawn_blocking;

use crate::{
models::crates::{CrateDep, CrateDeps, CrateName, CratePath, CrateRelease},
Expand Down Expand Up @@ -69,7 +68,8 @@ impl QueryCrate {
crate_name: CrateName,
) -> anyhow::Result<QueryCrateResponse> {
let crate_name2 = crate_name.clone();
let krate = spawn_blocking(move || index.crate_(crate_name2))
let krate = index
.crate_(crate_name2)
.await?
.ok_or_else(|| anyhow!("crate '{}' not found", crate_name.as_ref()))?;

Expand Down
14 changes: 6 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,13 @@ async fn main() {

let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), port);

let index = ManagedIndex::new();
let index = ManagedIndex::new(client.clone());

{
let index = index.clone();

tokio::spawn(async move {
index.refresh_at_interval(Duration::from_secs(20)).await;
});
}
// crates index health check
index
.crate_("libc".parse().unwrap())
.await
.expect("crates index startup check should succeed");

let mut engine = Engine::new(client.clone(), index);
engine.set_metrics(metrics);
Expand Down
6 changes: 6 additions & 0 deletions src/models/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ impl CratePath {
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CrateName(String);

impl CrateName {
pub(crate) fn as_str(&self) -> &str {
&self.0
}
}

impl From<CrateName> for String {
fn from(crate_name: CrateName) -> String {
crate_name.0
Expand Down
Loading

0 comments on commit 4ac7508

Please sign in to comment.