diff --git a/shed/sql/common/Cargo.toml b/shed/sql/common/Cargo.toml index 6aec931f8..9d99fb2d8 100644 --- a/shed/sql/common/Cargo.toml +++ b/shed/sql/common/Cargo.toml @@ -18,6 +18,7 @@ anyhow = "1.0.65" cloned = { version = "0.1.0", path = "../../cloned" } futures = { version = "0.3.22", features = ["async-await", "compat"] } futures_stats = { version = "0.1.0", path = "../../futures_stats" } +itertools = "0.10.3" lazy_static = "1.4" mysql_async = "0.27.1" mysql_derive = { version = "0.1.0", path = "../derive" } diff --git a/shed/sql/common/lib.rs b/shed/sql/common/lib.rs index 45c9090aa..f2a7bae7f 100644 --- a/shed/sql/common/lib.rs +++ b/shed/sql/common/lib.rs @@ -125,14 +125,14 @@ pub struct SqlShardedConnections { impl From> for SqlShardedConnections { fn from(shard_connections: Vec1) -> Self { let (head, last) = shard_connections.split_off_last(); - let mut write_connections = Vec::with_capacity(head.len()); - let mut read_connections = Vec::with_capacity(head.len()); - let mut read_master_connections = Vec::with_capacity(head.len()); - for connections in head { - write_connections.push(connections.write_connection); - read_connections.push(connections.read_connection); - read_master_connections.push(connections.read_master_connection); - } + let (write_connections, read_connections, read_master_connections) = + itertools::multiunzip(head.into_iter().map(|conn| { + ( + conn.write_connection, + conn.read_connection, + conn.read_master_connection, + ) + })); Self { read_connections: Vec1::from_vec_push(read_connections, last.read_connection),