Optimzing the user typing event in ShouldSendEvent() (#5560)
Этот коммит содержится в:
@@ -17,10 +17,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WRITE_WAIT = 30 * time.Second
|
WRITE_WAIT = 30 * time.Second
|
||||||
PONG_WAIT = 100 * time.Second
|
PONG_WAIT = 100 * time.Second
|
||||||
PING_PERIOD = (PONG_WAIT * 6) / 10
|
PING_PERIOD = (PONG_WAIT * 6) / 10
|
||||||
AUTH_TIMEOUT = 5 * time.Second
|
AUTH_TIMEOUT = 5 * time.Second
|
||||||
|
WEBCONN_MEMBER_CACHE_TIME = 1000 * 60 * 30 // 30 minutes
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebConn struct {
|
type WebConn struct {
|
||||||
@@ -198,15 +199,7 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
|||||||
|
|
||||||
// Only report events to users who are in the channel for the event
|
// Only report events to users who are in the channel for the event
|
||||||
if len(msg.Broadcast.ChannelId) > 0 {
|
if len(msg.Broadcast.ChannelId) > 0 {
|
||||||
|
if model.GetMillis()-webCon.LastAllChannelMembersTime > WEBCONN_MEMBER_CACHE_TIME {
|
||||||
// Only broadcast typing messages if less than 1K people in channel
|
|
||||||
if msg.Event == model.WEBSOCKET_EVENT_TYPING {
|
|
||||||
if Srv.Store.Channel().GetMemberCountFromCache(msg.Broadcast.ChannelId) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if model.GetMillis()-webCon.LastAllChannelMembersTime > 1000*60*15 { // 15 minutes
|
|
||||||
webCon.AllChannelMembers = nil
|
webCon.AllChannelMembers = nil
|
||||||
webCon.LastAllChannelMembersTime = 0
|
webCon.LastAllChannelMembersTime = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,18 +278,20 @@ func (h *Hub) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case msg := <-h.broadcast:
|
case msg := <-h.broadcast:
|
||||||
for _, webCon := range h.connections {
|
if OkToSendTypingMessage(msg) {
|
||||||
if webCon.ShouldSendEvent(msg) {
|
for _, webCon := range h.connections {
|
||||||
select {
|
if webCon.ShouldSendEvent(msg) {
|
||||||
case webCon.Send <- msg:
|
select {
|
||||||
default:
|
case webCon.Send <- msg:
|
||||||
l4g.Error(fmt.Sprintf("webhub.broadcast: cannot send, closing websocket for userId=%v", webCon.UserId))
|
default:
|
||||||
close(webCon.Send)
|
l4g.Error(fmt.Sprintf("webhub.broadcast: cannot send, closing websocket for userId=%v", webCon.UserId))
|
||||||
for i, webConCandidate := range h.connections {
|
close(webCon.Send)
|
||||||
if webConCandidate == webCon {
|
for i, webConCandidate := range h.connections {
|
||||||
h.connections[i] = h.connections[len(h.connections)-1]
|
if webConCandidate == webCon {
|
||||||
h.connections = h.connections[:len(h.connections)-1]
|
h.connections[i] = h.connections[len(h.connections)-1]
|
||||||
break
|
h.connections = h.connections[:len(h.connections)-1]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,3 +330,14 @@ func (h *Hub) Start() {
|
|||||||
|
|
||||||
go doRecoverableStart()
|
go doRecoverableStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OkToSendTypingMessage(msg *model.WebSocketEvent) bool {
|
||||||
|
// Only broadcast typing messages if less than 1K people in channel
|
||||||
|
if msg.Event == model.WEBSOCKET_EVENT_TYPING {
|
||||||
|
if Srv.Store.Channel().GetMemberCountFromCache(msg.Broadcast.ChannelId) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user