Skip to content

Commit

Permalink
Pass the CoreContext down
Browse files Browse the repository at this point in the history
Summary:
## This stack

We noticed that the poll time is pretty high on some async methods, and that is affecting other calls as well. Let's try to optimize that.

## This diff

Small diff in preparation to keep the next diffs in the stack small.

Reviewed By: lmvasquezg

Differential Revision: D67136286

fbshipit-source-id: 1e06190750151b30cd9fb8546fd7e47cc11983f2
  • Loading branch information
andreacampi authored and facebook-github-bot committed Dec 13, 2024
1 parent f9c7c9d commit a95b41e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions eden/mononoke/mononoke_api/src/sparse_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl SparseProfileMonitoring {
}
};
if paths_to_calculate.is_empty().not() {
let matchers = create_matchers(changeset, paths_to_calculate).await?;
let matchers = create_matchers(ctx, changeset, paths_to_calculate).await?;
let other_sizes = calculate_size(ctx, changeset, matchers).await?;
let res = self
.sql_sparse_profiles
Expand All @@ -234,6 +234,7 @@ impl SparseProfileMonitoring {
}

pub(crate) async fn fetch<R: MononokeRepo>(
_ctx: &CoreContext,
path: String,
changeset: &ChangesetContext<R>,
) -> Result<Option<Vec<u8>>> {
Expand All @@ -252,6 +253,7 @@ pub(crate) async fn fetch<R: MononokeRepo>(
}

async fn create_matchers<R: MononokeRepo>(
ctx: &CoreContext,
changeset: &ChangesetContext<R>,
paths: Vec<NonRootMPath>,
) -> Result<HashMap<String, Arc<dyn Matcher + Send + Sync>>> {
Expand All @@ -262,7 +264,7 @@ async fn create_matchers<R: MononokeRepo>(
let profile = sparse::Root::from_bytes(content.as_bytes(), dummy_source)
.with_context(|| format!("while constructing Profile for source {path}"))?;
let matcher = profile
.matcher(|path| fetch(path, changeset))
.matcher(|path| fetch(ctx, path, changeset))
.await
.with_context(|| format!("While constructing matcher for source {path}"))?;
anyhow::Ok((
Expand Down Expand Up @@ -448,7 +450,7 @@ pub async fn get_profile_delta_size<R: MononokeRepo>(
other: &ChangesetContext<R>,
paths: Vec<NonRootMPath>,
) -> Result<HashMap<String, ProfileSizeChange>, MononokeError> {
let matchers = create_matchers(current, paths).await?;
let matchers = create_matchers(ctx, current, paths).await?;
calculate_delta_size(ctx, monitor, current, other, matchers).await
}

Expand Down
6 changes: 4 additions & 2 deletions eden/mononoke/mononoke_api/src/test/test_sparse_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ async fn sparse_profile_parsing(fb: FacebookInit) -> Result<()> {
let changeset = ChangesetContext::new(repo_ctx, a);

let path = "sparse/include".to_string();
let content = fetch(path.clone(), &changeset).await?.unwrap();
let content = fetch(&ctx, path.clone(), &changeset).await?.unwrap();
let profile = sparse::Root::from_bytes(content, path)?;
let matcher = profile.matcher(|path| fetch(path, &changeset)).await?;
let matcher = profile
.matcher(|path| fetch(&ctx, path, &changeset))
.await?;

assert!(!matcher.matches_file(RepoPath::from_str("1")?)?);
assert!(!matcher.matches_file(RepoPath::from_str("dir1/file1")?)?);
Expand Down

0 comments on commit a95b41e

Please sign in to comment.