Minor improvement cache avoid clone (#479)

Avoid cloning to serialize to JSON; instead, dereference the object, as Serde
needs a reference to the object.
This commit is contained in:
César D. Rodas
2024-11-30 11:57:12 -03:00
committed by GitHub
parent af2fe580f4
commit 7d15587e3f
2 changed files with 7 additions and 10 deletions

View File

@@ -26,7 +26,9 @@ macro_rules! post_cache_wrapper {
state: State<MintState>,
payload: Json<$request_type>
) -> Result<Json<$response_type>, Response> {
let Json(json_extracted_payload) = payload.clone();
use std::ops::Deref;
let json_extracted_payload = payload.deref();
let State(mint_state) = state.clone();
let cache_key = serde_json::to_string(&json_extracted_payload).map_err(|err| {
into_response(Error::from(err))
@@ -37,11 +39,11 @@ macro_rules! post_cache_wrapper {
.expect("Shouldn't panic: response is json-deserializable.")));
}
let Json(response) = $handler(state, payload).await?;
mint_state.cache.insert(cache_key, serde_json::to_string(&response)
let response = $handler(state, payload).await?;
mint_state.cache.insert(cache_key, serde_json::to_string(response.deref())
.expect("Shouldn't panic: response is json-serializable.")
).await;
Ok(Json(response))
Ok(response)
}
}
};

View File

@@ -54,12 +54,7 @@ impl WsHandle for Method {
return Err(WsError::InvalidParams);
}
let mut subscription = context
.state
.mint
.pubsub_manager
.subscribe(self.0.clone())
.await;
let mut subscription = context.state.mint.pubsub_manager.subscribe(self.0).await;
let publisher = context.publisher.clone();
context.subscriptions.insert(
sub_id.clone(),