Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract creation of CurrentConfiguration to shared method #96

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ impl CurrentConfiguration {
}
}

impl CurrentConfiguration {
async fn for_config(
db_config: BeamlineConfiguration,
nt: &NumTracker,
) -> async_graphql::Result<Self> {
let dir = nt
.for_beamline(db_config.name(), db_config.tracker_file_extension())
.await?;
let high_file = dir.prev().await?;
Ok(CurrentConfiguration {
db_config,
high_file,
})
}
}

impl FieldSource<ScanField> for ScanPaths {
fn resolve(&self, field: &ScanField) -> Cow<'_, str> {
match field {
Expand Down Expand Up @@ -346,14 +362,7 @@ impl Query {
let nt = ctx.data::<NumTracker>()?;
trace!("Getting config for {beamline:?}");
let conf = db.current_configuration(&beamline).await?;
let dir = nt
.for_beamline(&beamline, conf.tracker_file_extension())
.await?;
let high_file = dir.prev().await?;
Ok(CurrentConfiguration {
db_config: conf,
high_file,
})
CurrentConfiguration::for_config(conf, nt).await
}

/// Get the configurations for all available beamlines
Expand All @@ -372,16 +381,11 @@ impl Query {
None => db.all_configurations().await?,
};

futures::future::join_all(configurations.into_iter().map(|cnf| async {
let dir = nt
.for_beamline(cnf.name(), cnf.tracker_file_extension())
.await?;
let high_file = dir.prev().await?;
Ok(CurrentConfiguration {
db_config: cnf,
high_file,
})
}))
futures::future::join_all(
configurations
.into_iter()
.map(|cnf| CurrentConfiguration::for_config(cnf, nt)),
)
.await
.into_iter()
.collect()
Expand Down Expand Up @@ -448,14 +452,7 @@ impl Mutation {
Some(bc) => bc,
None => upd.insert_new(db).await?,
};
let dir = nt
.for_beamline(&beamline, db_config.tracker_file_extension())
.await?;
let high_file = dir.prev().await?;
Ok(CurrentConfiguration {
db_config,
high_file,
})
CurrentConfiguration::for_config(db_config, nt).await
}
}

Expand Down
Loading