- nodes = {cr[:uuid] => cr}
- @svg = ProvenanceHelper::create_provenance_graph nodes,
- "provenance_svg",
- {
- :request => request,
- :direction => :top_down,
- }
+ nodes = {}
+ child_crs = []
+ col_uuids = []
+ col_pdhs = []
+ col_uuids << cr[:output_uuid] if cr[:output_uuid]
+ col_pdhs += ProvenanceHelper::cr_input_pdhs(cr)
+
+ # Search for child CRs
+ if cr[:container_uuid]
+ child_crs = ContainerRequest.where(requesting_container_uuid: cr[:container_uuid]).with_count("none")
+
+ child_crs.each do |child|
+ nodes[child[:uuid]] = child
+ col_uuids << child[:output_uuid] if child[:output_uuid]
+ col_pdhs += ProvenanceHelper::cr_input_pdhs(child)
+ end
+ end
+
+ if nodes.length == 0
+ nodes[cr[:uuid]] = cr
+ end
+
+ pdh_to_col = {} # Indexed by PDH
+ output_pdhs = []
+
+ # Batch requests to get all related collections
+ # First fetch output collections by UUID.
+ Collection.filter([['uuid', 'in', col_uuids.uniq]]).with_count("none").each do |c|
+ output_pdhs << c[:portable_data_hash]
+ pdh_to_col[c[:portable_data_hash]] = c
+ nodes[c[:uuid]] = c
+ end
+ # Next, get input collections by PDH.
+ Collection.filter(
+ [['portable_data_hash', 'in', col_pdhs - output_pdhs]]).with_count("none").each do |c|
+ nodes[c[:portable_data_hash]] = c
+ end
+
+ @svg = ProvenanceHelper::create_provenance_graph(
+ nodes, "provenance_svg",
+ {
+ :request => request,
+ :pdh_to_uuid => pdh_to_col,
+ }
+ )