Skip to content

Commit

Permalink
feat: eagerly pull some tagged objects when scanning imports during c…
Browse files Browse the repository at this point in the history
…heckin

- resolves #440
  • Loading branch information
m-hilgendorf committed Jan 15, 2025
1 parent 7e23195 commit e645782
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/server/src/artifact/checkin/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ impl Server {
Some(analysis.imports)
};

// Pre-emptively pull tags for the set of imports.
if let Some(imports) = &imports {
let imports = imports.clone();
let server = self.clone();
tokio::spawn(async move {
server
.pull_tags_from_imports(imports)
.await
.inspect_err(|error| tracing::error!(%error, "failed to pull tags"))
.ok();
});
}

// Try and get the references of this file in the lockfile, if it exists.
let resolved_references = 'a: {
// Break if no lockfile is present.
Expand Down Expand Up @@ -696,6 +709,29 @@ impl Server {
}
}

impl Server {
async fn pull_tags_from_imports(
&self,
imports: impl IntoIterator<Item = tg::Import>,
) -> tg::Result<()> {
imports
.into_iter()
.filter_map(|import| {
let server = self.clone();
let remote = import
.reference
.options()
.and_then(|options| options.remote.clone());
let pattern = import.reference.item().try_unwrap_tag_ref().ok()?.clone();
let future = async move { server.pull_tag(pattern, remote).await };
Some(future)
})
.collect::<FuturesUnordered<_>>()
.try_collect()
.await
}
}

impl Graph {
// Find the roots of every node.
fn find_roots(&mut self) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/tag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod delete;
pub mod get;
pub mod list;
pub mod pull;
pub mod put;

0 comments on commit e645782

Please sign in to comment.