From 30722e10133ef86617f6ce9e3f1681abf8eca62b Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 13 May 2019 15:13:27 +1000 Subject: [PATCH] Stop wol rebuild from firing so frequently. --- common/widget_wol.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/common/widget_wol.go b/common/widget_wol.go index a025161e..9ac6b68d 100644 --- a/common/widget_wol.go +++ b/common/widget_wol.go @@ -2,6 +2,7 @@ package common import ( "bytes" + //"log" "net/http/httptest" "github.com/Azareal/Gosora/common/phrases" @@ -20,7 +21,7 @@ func wolInit(widget *Widget, schedule *WidgetScheduler) error { return nil } -func wolGetUsers() ([]*User,int) { +func wolGetUsers() ([]*User, int) { ucount := WsHub.UserCount() // We don't want a ridiculously long list, so we'll show the number if it's too high and only show staff individually var users []*User @@ -56,15 +57,23 @@ var wolLastUsers []*User func wolTick(widget *Widget) error { w := httptest.NewRecorder() users, ucount := wolGetUsers() - //log.Printf("users: %+v\n",users) - //log.Printf("wolLastUsers: %+v\n",wolLastUsers) + + var inOld = func(id int) bool { + for _, user := range wolLastUsers { + if id == user.ID { + return true + } + } + return false + } // Avoid rebuilding the widget, if the users are exactly the same as on the last tick if len(users) == len(wolLastUsers) { diff := false - for i, user := range users { - if user.ID != wolLastUsers[i].ID { + for _, user := range users { + if !inOld(user.ID) { diff = true + break } } if !diff { @@ -77,6 +86,8 @@ func wolTick(widget *Widget) error { } } } + //log.Printf("users: %+v\n", users) + //log.Printf("wolLastUsers: %+v\n", wolLastUsers) wol := &wolUsers{SimpleDefaultHeader(w), phrases.GetTmplPhrase("widget.online_name"), users, ucount} err := wol.Header.Theme.RunTmpl("widget_online", wol, wol.Header.Writer)