From f42e72927a86fc90cd1f09b66df550a515b94887 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Thu, 26 Sep 2024 10:57:58 +0200 Subject: [PATCH] Perform a single pre-fretch for some watches Signed-off-by: R.I.Pienaar --- cli/server_watch_js_command.go | 16 +++++++++++++++- cli/server_watch_srv_command.go | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cli/server_watch_js_command.go b/cli/server_watch_js_command.go index 84fbd351..d0b7d6db 100644 --- a/cli/server_watch_js_command.go +++ b/cli/server_watch_js_command.go @@ -90,14 +90,28 @@ func (c *SrvWatchJSCmd) updateSizes() error { return nil } +func (c *SrvWatchJSCmd) prePing(nc *nats.Conn, h nats.MsgHandler) { + sub, err := nc.Subscribe(nc.NewRespInbox(), h) + if err != nil { + return + } + + time.AfterFunc(2*time.Second, func() { sub.Unsubscribe() }) + + msg := nats.NewMsg("$SYS.REQ.SERVER.PING") + msg.Reply = sub.Subject + nc.PublishMsg(msg) +} + func (c *SrvWatchJSCmd) jetstreamAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return err } - _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) + c.prePing(nc, c.handle) + _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) if err != nil { return err } diff --git a/cli/server_watch_srv_command.go b/cli/server_watch_srv_command.go index add91721..357a61ee 100644 --- a/cli/server_watch_srv_command.go +++ b/cli/server_watch_srv_command.go @@ -95,12 +95,28 @@ func (c *SrvWatchServerCmd) updateSizes() error { return nil } + +func (c *SrvWatchServerCmd) prePing(nc *nats.Conn, h nats.MsgHandler) { + sub, err := nc.Subscribe(nc.NewRespInbox(), h) + if err != nil { + return + } + + time.AfterFunc(2*time.Second, func() { sub.Unsubscribe() }) + + msg := nats.NewMsg("$SYS.REQ.SERVER.PING") + msg.Reply = sub.Subject + nc.PublishMsg(msg) +} + func (c *SrvWatchServerCmd) serversAction(_ *fisk.ParseContext) error { nc, _, err := prepareHelper("", natsOpts()...) if err != nil { return err } + c.prePing(nc, c.handle) + _, err = nc.Subscribe("$SYS.SERVER.*.STATSZ", c.handle) if err != nil {