Skip to content

Commit

Permalink
Merge pull request #194 from 56quarters/fewer-clones
Browse files Browse the repository at this point in the history
Remove some unnecessary clones from the high-level client
  • Loading branch information
56quarters authored Dec 29, 2024
2 parents 744c543 + 1d91bca commit a618074
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions mtop-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,22 @@ macro_rules! operation_for_all {
let servers = $self.selector.servers().await;
let tasks = servers
.into_iter()
.map(|server| (server.clone(), spawn_for_host!($self, $method, &server)))
.map(|server| (server.id().clone(), spawn_for_host!($self, $method, &server)))
.collect::<Vec<_>>();

let mut values = HashMap::with_capacity(tasks.len());
let mut errors = HashMap::new();

for (server, task) in tasks {
for (id, task) in tasks {
match task.await {
Ok(Ok(results)) => {
values.insert(server.id().clone(), results);
values.insert(id, results);
}
Ok(Err(e)) => {
errors.insert(server.id().clone(), e);
errors.insert(id, e);
}
Err(e) => {
errors.insert(
server.id().clone(),
MtopError::runtime_cause("fetching cluster values", e),
);
errors.insert(id, MtopError::runtime_cause("fetching cluster values", e));
}
};
}
Expand Down Expand Up @@ -349,22 +346,22 @@ where

let tasks = by_server
.into_iter()
.map(|(server, keys)| (server.clone(), spawn_for_host!(self, get, &server, &keys)))
.map(|(server, keys)| (server.id().clone(), spawn_for_host!(self, get, &server, &keys)))
.collect::<Vec<_>>();

let mut values = HashMap::with_capacity(num_keys);
let mut errors = HashMap::new();

for (server, task) in tasks {
for (id, task) in tasks {
match task.await {
Ok(Ok(results)) => {
values.extend(results);
}
Ok(Err(e)) => {
errors.insert(server.id().clone(), e);
errors.insert(id, e);
}
Err(e) => {
errors.insert(server.id().clone(), MtopError::runtime_cause("fetching keys", e));
errors.insert(id, MtopError::runtime_cause("fetching keys", e));
}
};
}
Expand Down

0 comments on commit a618074

Please sign in to comment.