Batch push websocket to improve performance

This commit is contained in:
2024-07-17 11:58:51 +08:00
parent d97837dab6
commit 96b96912ed
11 changed files with 200 additions and 230 deletions

View File

@ -1,9 +1,10 @@
package services
import (
"sync"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/models"
"github.com/gofiber/contrib/websocket"
"sync"
)
var (
@ -44,3 +45,17 @@ func WebsocketPush(uid uint, body []byte) (count int, success int, errs []error)
}
return
}
func WebsocketPushBatch(uidList []uint, body []byte) (count int, success int, errs []error) {
for _, uid := range uidList {
for conn := range wsConn[uid] {
if err := conn.WriteMessage(1, body); err != nil {
errs = append(errs, err)
} else {
success++
}
count++
}
}
return
}