3987 Reduce read lock duration (#4328)
This commit is contained in:
parent
1baf7848db
commit
41128094d1
1 changed files with 11 additions and 2 deletions
|
@ -54,9 +54,18 @@ pub(crate) async fn notifications(state: Arc<RpcState>, canceller: CancellationT
|
||||||
// Receive a notification on the channel
|
// Receive a notification on the channel
|
||||||
Ok(notification) = channel.recv() => {
|
Ok(notification) = channel.recv() => {
|
||||||
// Find which WebSocket the notification belongs to
|
// Find which WebSocket the notification belongs to
|
||||||
if let Some(id) = state.live_queries.read().await.get(¬ification.id) {
|
let found_ws = {
|
||||||
|
// We remove the lock asap
|
||||||
|
state.live_queries.read().await.get(¬ification.id).cloned()
|
||||||
|
};
|
||||||
|
if let Some(id) = found_ws {
|
||||||
// Check to see if the WebSocket exists
|
// Check to see if the WebSocket exists
|
||||||
if let Some(rpc) = state.web_sockets.read().await.get(id) {
|
let maybe_ws = {
|
||||||
|
// We remove the lock ASAP
|
||||||
|
// WS is an Arc anyway
|
||||||
|
state.web_sockets.read().await.get(&id).cloned()
|
||||||
|
};
|
||||||
|
if let Some(rpc) = maybe_ws {
|
||||||
// Serialize the message to send
|
// Serialize the message to send
|
||||||
let message = success(None, notification);
|
let message = success(None, notification);
|
||||||
// Add metrics
|
// Add metrics
|
||||||
|
|
Loading…
Reference in a new issue