Skip to content

Commit

Permalink
Merge pull request #1162 from ripienaar/pre_fetch_watch
Browse files Browse the repository at this point in the history
Perform a single pre-fretch for some watches
  • Loading branch information
ripienaar authored Sep 26, 2024
2 parents 9aeb804 + f42e729 commit db5dbae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cli/server_watch_js_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions cli/server_watch_srv_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit db5dbae

Please sign in to comment.