Skip to content

Commit 8bcaee1

Browse files
committed
editoast: collect early
The macro was doing the job of collecting. However, most of the objects sent are already collected before calling the macro which creates twice the allocations.
1 parent eea95d4 commit 8bcaee1

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

editoast/editoast_derive/src/modelv2/codegen/create_batch_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl ToTokens for CreateBatchImpl {
3939
use diesel::prelude::*;
4040
use diesel_async::RunQueryDsl;
4141
use futures_util::stream::TryStreamExt;
42+
let values = values.into_iter().collect::<Vec<_>>();
4243
Ok(crate::chunked_for_libpq! {
4344
#field_count,
4445
values,

editoast/src/modelsv2/prelude/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ macro_rules! chunked_for_libpq {
128128
const ASYNC_SUBDIVISION: usize = 2_usize;
129129
const CHUNK_SIZE: usize = LIBPQ_MAX_PARAMETERS / ASYNC_SUBDIVISION / $parameters_per_row;
130130
let mut result = Vec::new();
131-
let values = $values.into_iter().collect::<Vec<_>>();
132-
let chunks = values.chunks(CHUNK_SIZE);
133-
for $chunk in chunks.into_iter() {
131+
let chunks = $values.chunks(CHUNK_SIZE);
132+
for $chunk in chunks {
134133
let chunk_result = $query;
135134
result.push(chunk_result);
136135
}
@@ -143,9 +142,8 @@ macro_rules! chunked_for_libpq {
143142
const ASYNC_SUBDIVISION: usize = 2_usize;
144143
const CHUNK_SIZE: usize = LIBPQ_MAX_PARAMETERS / ASYNC_SUBDIVISION / $parameters_per_row;
145144
let mut result = $result;
146-
let values = $values.into_iter().collect::<Vec<_>>();
147-
let chunks = values.chunks(CHUNK_SIZE);
148-
for $chunk in chunks.into_iter() {
145+
let chunks = $values.chunks(CHUNK_SIZE);
146+
for $chunk in chunks {
149147
let chunk_result = $query;
150148
result.extend(chunk_result);
151149
}

0 commit comments

Comments
 (0)