From e16bebb8df822b0c31a3456ee28a592a12b90318 Mon Sep 17 00:00:00 2001 From: alexpantyukhin Date: Wed, 7 Apr 2021 11:48:39 +0400 Subject: [PATCH] extract update remote subscription. --- server/client.go | 18 +++--------------- server/server.go | 9 +++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/server/client.go b/server/client.go index dac5d8d9..62ef4877 100644 --- a/server/client.go +++ b/server/client.go @@ -2522,11 +2522,7 @@ func (c *client) addShadowSub(sub *subscription, ime *ime) (*subscription, error } // Update our route map here. - c.srv.updateRouteSubscriptionMap(im.acc, &nsub, 1) - if c.srv.gateway.enabled { - c.srv.gatewayUpdateSubInterest(im.acc.Name, &nsub, 1) - } - c.srv.updateLeafNodes(im.acc, &nsub, 1) + c.srv.updateRemoteSubscription(im.acc, &nsub, 1) return &nsub, nil } @@ -2972,11 +2968,7 @@ func (c *client) deliverMsg(sub *subscription, subject, reply, mh, msg []byte, g // Due to defer, reverse the code order so that execution // is consistent with other cases where we unsubscribe. if shouldForward { - if srv.gateway.enabled { - defer srv.gatewayUpdateSubInterest(client.acc.Name, sub, -1) - } - defer srv.updateRouteSubscriptionMap(client.acc, sub, -1) - defer srv.updateLeafNodes(client.acc, sub, -1) + defer srv.updateRemoteSubscription(client.acc, sub, -1) } defer client.unsubscribe(client.acc, sub, true, true) } else if sub.nm > sub.max { @@ -2984,11 +2976,7 @@ func (c *client) deliverMsg(sub *subscription, subject, reply, mh, msg []byte, g client.mu.Unlock() client.unsubscribe(client.acc, sub, true, true) if shouldForward { - srv.updateRouteSubscriptionMap(client.acc, sub, -1) - if srv.gateway.enabled { - srv.gatewayUpdateSubInterest(client.acc.Name, sub, -1) - } - srv.updateLeafNodes(client.acc, sub, -1) + srv.updateRemoteSubscription(client.acc, sub, -1) } return false } diff --git a/server/server.go b/server/server.go index 30b8f04c..cbf5de86 100644 --- a/server/server.go +++ b/server/server.go @@ -3356,3 +3356,12 @@ func (s *Server) setFirstPingTimer(c *client) { d += time.Duration(addDelay) c.ping.tmr = time.AfterFunc(d, c.processPingTimer) } + +func (s *Server) updateRemoteSubscription(acc *Account, sub *subscription, delta int32) { + s.updateRouteSubscriptionMap(acc, sub, delta) + if s.gateway.enabled { + s.gatewayUpdateSubInterest(acc.Name, sub, delta) + } + + s.updateLeafNodes(acc, sub, delta) +}