Skip to content

Commit

Permalink
Reduce cloning in nested read
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn committed Feb 26, 2020
1 parent 6cf3607 commit 7729938
Showing 1 changed file with 4 additions and 6 deletions.
Expand Up @@ -176,18 +176,17 @@ pub async fn one2m<'a, 'b>(
// Inlining is done on the parent, this means that we need to write the primary parent ID
// into the child records that we retrieved. The matching is done based on the parent link values.
if parent_field.is_inlined_on_enclosing_model() {
let child_field_names = scalars.field_names.clone();
let mut additional_records = vec![];

for mut record in scalars.records.iter_mut() {
let child_link: RecordIdentifier = record.identifier(&child_field_names, &child_link_id)?;
let child_link_values: Vec<PrismaValue> = child_link.pairs.iter().map(|(_, v)| v.clone()).collect();
let child_link: RecordIdentifier = record.identifier(&scalars.field_names, &child_link_id)?;
let child_link_values: Vec<PrismaValue> = child_link.pairs.into_iter().map(|(_, v)| v).collect();

if let Some(parent_ids) = link_mapping.get_mut(&child_link_values) {
parent_ids.reverse();

let parent_id = parent_ids.pop().unwrap();
record.parent_id = Some(parent_id.clone());
record.parent_id = Some(parent_id);

for parent_id in parent_ids {
let mut record = record.clone();
Expand All @@ -204,11 +203,10 @@ pub async fn one2m<'a, 'b>(
paginator.apply_pagination(&mut scalars);
} else if parent_field.related_field().is_inlined_on_enclosing_model() {
let parent_identifier = parent_field.model().primary_identifier();
let field_names = scalars.field_names.clone();
let child_link_fields = parent_field.related_field().linking_fields();

for record in scalars.records.iter_mut() {
let parent_id: RecordIdentifier = record.identifier(&field_names, &child_link_fields)?;
let parent_id: RecordIdentifier = record.identifier(&scalars.field_names, &child_link_fields)?;
let parent_id = parent_id
.into_iter()
.zip(parent_identifier.data_source_fields())
Expand Down

0 comments on commit 7729938

Please sign in to comment.