Skip to content

Commit

Permalink
Use a re-usable client connection pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmcwhirter committed Oct 4, 2024
1 parent f0e8a45 commit cb678fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 12 additions & 3 deletions modules/importer/src/runner/clearly_defined/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct ClearlyDefinedWalker<P: Progress + Send + 'static> {
progress_instance: Option<P::Instance>,
report: Arc<Mutex<ReportBuilder>>,
coordinates_seen_this_run: HashSet<String>,
client: reqwest::Client,
}

impl<P: Progress + Send + 'static> ClearlyDefinedWalker<P> {
Expand All @@ -35,6 +36,7 @@ impl<P: Progress + Send + 'static> ClearlyDefinedWalker<P> {
progress_instance: None,
report,
coordinates_seen_this_run: Default::default(),
client: Default::default(),
}
}

Expand All @@ -44,7 +46,10 @@ impl<P: Progress + Send + 'static> ClearlyDefinedWalker<P> {
}

pub async fn run(mut self) -> Result<ClearlyDefinedItemContinuation, Error> {
let changes = reqwest::get(self.changes_index_url()).await?;
let changes = self
.client
.execute(self.client.get(self.changes_index_url()).build()?)
.await?;

let changes = changes.bytes().await?;

Expand Down Expand Up @@ -76,7 +81,11 @@ impl<P: Progress + Send + 'static> ClearlyDefinedWalker<P> {
pub async fn load_changes(&mut self, date: &str) -> Result<(), Error> {
let changes_url = self.changes_url(date);

let changeset = reqwest::get(changes_url).await?;
let changeset = self
.client
.execute(self.client.get(changes_url).build()?)
.await?;

let changeset = changeset.bytes().await?;

for line in changeset.lines().map_while(Result::ok) {
Expand All @@ -93,7 +102,7 @@ impl<P: Progress + Send + 'static> ClearlyDefinedWalker<P> {

let url = self.coordinate_url(coordinate);

let item = reqwest::get(url).await?;
let item = self.client.execute(self.client.get(url).build()?).await?;

let content = item.bytes().await?;
let mut body = Vec::new();
Expand Down
2 changes: 0 additions & 2 deletions modules/ingestor/src/service/sbom/clearly_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ impl<'g> ClearlyDefinedLoader<'g> {
});
}

println!("{:#?}", item);

let id_path = JsonPath::from_str("$._id")?;
let license_path = JsonPath::from_str("$.licensed.declared")?;

Expand Down

0 comments on commit cb678fa

Please sign in to comment.