Skip to content

Commit 76d8c57

Browse files
committed
refactor: clean up some code in QueryExt::select_ids
1. There was no need to use `drain` since we own the vector itself and not a mutable reference to it, just `for row in rows` would have been fine. 2. Rather than creating the second vector and using a loop to push transformed values, using `map` is more idiomatic (and efficient in this case, too, since the vec was created with `Vec::new` instead of `Vec::with_capacity`). 3. The TODO comment seemed outdated, there are no queries to add tracing too in this function.
1 parent c238eea commit 76d8c57

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

query-engine/connectors/sql-query-connector/src/query_ext.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,14 @@ impl<Q: Queryable + ?Sized> QueryExt for Q {
135135
let field_names: Vec<_> = model_id.fields().map(|field| field.name()).collect();
136136
let meta = column_metadata::create(field_names.as_slice(), &idents);
137137

138-
// TODO: Add tracing
139-
let mut rows = self.filter(select.into(), &meta, ctx).await?;
140-
let mut result = Vec::new();
141-
142-
for row in rows.drain(0..) {
143-
let tuples: Vec<_> = model_id.scalar_fields().zip(row.values.into_iter()).collect();
144-
let record_id: SelectionResult = SelectionResult::new(tuples);
145-
146-
result.push(record_id);
147-
}
138+
let rows = self.filter(select.into(), &meta, ctx).await?;
139+
let result = rows
140+
.into_iter()
141+
.map(|row| {
142+
let tuples = model_id.scalar_fields().zip(row.values.into_iter()).collect();
143+
SelectionResult::new(tuples)
144+
})
145+
.collect();
148146

149147
Ok(result)
150148
}

0 commit comments

Comments
 (0)