Skip to content

Commit

Permalink
Return the result of the graph loads a Vec instead of a HashMap
Browse files Browse the repository at this point in the history
This allows test results to be consistent.

Signed-off-by: Hiram Chirino <[email protected]>
  • Loading branch information
chirino committed Jan 31, 2025
1 parent ec8d171 commit 5319ce7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions modules/analysis/src/service/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl AnalysisService {
&self,
connection: &C,
query: GraphQuery<'_>,
) -> Result<HashMap<String, Arc<PackageGraph>>, Error> {
) -> Result<Vec<(String, Arc<PackageGraph>)>, Error> {
let search_sbom_subquery = match query {
GraphQuery::Component(ComponentReference::Id(name)) => sbom_node::Entity::find()
.filter(sbom_node::Column::NodeId.eq(name))
Expand Down Expand Up @@ -198,7 +198,7 @@ impl AnalysisService {
&self,
connection: &C,
subquery: SelectStatement,
) -> Result<HashMap<String, Arc<PackageGraph>>, Error> {
) -> Result<Vec<(String, Arc<PackageGraph>)>, Error> {
let distinct_sbom_ids: Vec<String> = sbom::Entity::find()
.filter(sbom::Column::SbomId.in_subquery(subquery))
.select()
Expand Down Expand Up @@ -341,13 +341,13 @@ impl AnalysisService {
&self,
connection: &C,
distinct_sbom_ids: &Vec<String>,
) -> Result<HashMap<String, Arc<PackageGraph>>, DbErr> {
let mut results = HashMap::new();
) -> Result<Vec<(String, Arc<PackageGraph>)>, DbErr> {
let mut results = Vec::new();
for distinct_sbom_id in distinct_sbom_ids {
results.insert(
results.push((
distinct_sbom_id.clone(),
self.load_graph(connection, distinct_sbom_id).await?,
);
));
}
Ok(results)
}
Expand Down
10 changes: 5 additions & 5 deletions modules/analysis/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl AnalysisService {
pub async fn load_all_graphs<C: ConnectionTrait>(
&self,
connection: &C,
) -> Result<HashMap<String, Arc<PackageGraph>>, DbErr> {
) -> Result<Vec<(String, Arc<PackageGraph>)>, DbErr> {
// retrieve all sboms in trustify

let distinct_sbom_ids = sbom::Entity::find()
Expand Down Expand Up @@ -233,7 +233,7 @@ impl AnalysisService {
fn collect_graph<'a, T, I, C>(
&self,
query: impl Into<GraphQuery<'a>> + Debug,
graphs: HashMap<String, Arc<PackageGraph>>,
graphs: Vec<(String, Arc<PackageGraph>)>,
init: I,
collector: C,
) -> T
Expand All @@ -255,7 +255,7 @@ impl AnalysisService {
fn query_graph<'a, F>(
&self,
query: impl Into<GraphQuery<'a>> + Debug,
graphs: HashMap<String, Arc<PackageGraph>>,
graphs: Vec<(String, Arc<PackageGraph>)>,
mut f: F,
) where
F: FnMut(&Graph<PackageNode, Relationship>, NodeIndex, &PackageNode),
Expand Down Expand Up @@ -294,7 +294,7 @@ impl AnalysisService {
pub fn query_ancestor_graph<'a>(
&self,
query: impl Into<GraphQuery<'a>> + Debug,
graphs: HashMap<String, Arc<PackageGraph>>,
graphs: Vec<(String, Arc<PackageGraph>)>,
) -> Vec<AncestorSummary> {
self.collect_graph(
query,
Expand All @@ -313,7 +313,7 @@ impl AnalysisService {
pub async fn query_deps_graph(
&self,
query: impl Into<GraphQuery<'_>> + Debug,
graphs: HashMap<String, Arc<PackageGraph>>,
graphs: Vec<(String, Arc<PackageGraph>)>,
) -> Vec<DepSummary> {
self.collect_graph(
query,
Expand Down

0 comments on commit 5319ce7

Please sign in to comment.