mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-21 22:21:41 +00:00
localapi: reduce garbage production in bus watcher
Updates #optimization Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
parent
3f7313dbdb
commit
e0f97738ee
@ -1292,13 +1292,11 @@ func (h *Handler) serveWatchIPNBus(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
h.b.WatchNotifications(ctx, mask, f.Flush, func(roNotify *ipn.Notify) (keepGoing bool) {
|
h.b.WatchNotifications(ctx, mask, f.Flush, func(roNotify *ipn.Notify) (keepGoing bool) {
|
||||||
js, err := json.Marshal(roNotify)
|
err := enc.Encode(roNotify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logf("json.Marshal: %v", err)
|
h.logf("json.Encode: %v", err)
|
||||||
return false
|
|
||||||
}
|
|
||||||
if _, err := fmt.Fprintf(w, "%s\n", js); err != nil {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
f.Flush()
|
f.Flush()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user