Remove mut where possible, parallel cache requests (#668)

This commit is contained in:
Drazen Urch
2021-07-02 10:50:49 +02:00
committed by GitHub
parent f08f19cd86
commit 3aafe54887
7 changed files with 16 additions and 28 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ async fn gateway_details(
chosen_gateway_id: Option<&str>,
) -> gateway::Node {
let validator_client_config = validator_client::Config::new(validator_servers, mixnet_contract);
let mut validator_client = validator_client::Client::new(validator_client_config);
let validator_client = validator_client::Client::new(validator_client_config);
let gateways = validator_client.get_gateways().await.unwrap();
let valid_gateways = gateways
+1 -1
View File
@@ -110,7 +110,7 @@ async fn gateway_details(
chosen_gateway_id: Option<&str>,
) -> gateway::Node {
let validator_client_config = validator_client::Config::new(validator_servers, mixnet_contract);
let mut validator_client = validator_client::Client::new(validator_client_config);
let validator_client = validator_client::Client::new(validator_client_config);
let gateways = validator_client.get_gateways().await.unwrap();
let valid_gateways = gateways
+1 -1
View File
@@ -255,7 +255,7 @@ impl NymClient {
vec![self.validator_server.clone()],
&self.mixnet_contract_address,
);
let mut validator_client = validator_client::Client::new(validator_client_config);
let validator_client = validator_client::Client::new(validator_client_config);
let mixnodes = match validator_client.get_mix_nodes().await {
Err(err) => panic!("{}", err),
@@ -153,7 +153,7 @@ impl Client {
}
async fn get_mix_nodes_paged(
&mut self,
&self,
start_after: Option<IdentityKey>,
) -> Result<PagedMixnodeResponse, ValidatorClientError> {
let query_content_json = serde_json::to_string(&QueryRequest::GetMixNodes {
@@ -168,7 +168,7 @@ impl Client {
self.query_validators(query_content).await
}
pub async fn get_mix_nodes(&mut self) -> Result<Vec<MixNodeBond>, ValidatorClientError> {
pub async fn get_mix_nodes(&self) -> Result<Vec<MixNodeBond>, ValidatorClientError> {
let mut mixnodes = Vec::new();
let mut start_after = None;
loop {
@@ -186,7 +186,7 @@ impl Client {
}
async fn get_gateways_paged(
&mut self,
&self,
start_after: Option<IdentityKey>,
) -> Result<PagedGatewayResponse, ValidatorClientError> {
let query_content_json = serde_json::to_string(&QueryRequest::GetGateways {
@@ -201,7 +201,7 @@ impl Client {
self.query_validators(query_content).await
}
pub async fn get_gateways(&mut self) -> Result<Vec<GatewayBond>, ValidatorClientError> {
pub async fn get_gateways(&self) -> Result<Vec<GatewayBond>, ValidatorClientError> {
let mut gateways = Vec::new();
let mut start_after = None;
loop {
@@ -218,9 +218,7 @@ impl Client {
Ok(gateways)
}
pub async fn get_layer_distribution(
&mut self,
) -> Result<LayerDistribution, ValidatorClientError> {
pub async fn get_layer_distribution(&self) -> Result<LayerDistribution, ValidatorClientError> {
// serialization of an empty enum can't fail...
let query_content_json =
serde_json::to_string(&QueryRequest::LayerDistribution {}).unwrap();
+1 -1
View File
@@ -137,7 +137,7 @@ impl Gateway {
self.config.get_validator_rest_endpoints(),
self.config.get_validator_mixnet_contract_address(),
);
let mut validator_client = validator_client::Client::new(validator_client_config);
let validator_client = validator_client::Client::new(validator_client_config);
let existing_gateways = match validator_client.get_gateways().await {
Ok(gateways) => gateways,
+1 -1
View File
@@ -183,7 +183,7 @@ impl MixNode {
self.config.get_validator_rest_endpoints(),
self.config.get_validator_mixnet_contract_address(),
);
let mut validator_client = validator_client::Client::new(validator_client_config);
let validator_client = validator_client::Client::new(validator_client_config);
let existing_nodes = match validator_client.get_mix_nodes().await {
Ok(nodes) => nodes,
+6 -16
View File
@@ -39,22 +39,12 @@ impl ValidatorCache {
}
pub async fn cache(&mut self) -> Result<()> {
// We need to make validator_api non mut first
// tokio::join!(self.cache_mixnodes(), self.cache_gateways());
self.cache_mixnodes().await?;
self.cache_gateways().await?;
Ok(())
}
async fn cache_mixnodes(&mut self) -> Result<()> {
let mixnodes = self.validator_client.get_mix_nodes().await?;
self.mixnodes.set(mixnodes);
Ok(())
}
async fn cache_gateways(&mut self) -> Result<()> {
let gateways = self.validator_client.get_gateways().await?;
self.gateways.set(gateways);
let (mixnodes, gateways) = tokio::join!(
self.validator_client.get_mix_nodes(),
self.validator_client.get_gateways()
);
self.mixnodes.set(mixnodes?);
self.gateways.set(gateways?);
Ok(())
}