summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-28 17:49:25 -0500
committerGitHub <noreply@github.com>2017-02-28 17:49:25 -0500
commit838bb8cee2dbfb5c1f6560154a603fcc000f6244 (patch)
tree6a670693d0b435d22c36a2ead26a1d34c66f8136
parentd6d603d8cfd82d7a281757cceae08c8b7938d16a (diff)
downloadchat-838bb8cee2dbfb5c1f6560154a603fcc000f6244.tar.gz
chat-838bb8cee2dbfb5c1f6560154a603fcc000f6244.tar.bz2
chat-838bb8cee2dbfb5c1f6560154a603fcc000f6244.zip
Optimzing the user typing event in ShouldSendEvent() (#5560)
-rw-r--r--app/web_conn.go19
-rw-r--r--app/web_hub.go37
2 files changed, 31 insertions, 25 deletions
diff --git a/app/web_conn.go b/app/web_conn.go
index 02c3b2642..5205ac2ee 100644
--- a/app/web_conn.go
+++ b/app/web_conn.go
@@ -17,10 +17,11 @@ import (
)
const (
- WRITE_WAIT = 30 * time.Second
- PONG_WAIT = 100 * time.Second
- PING_PERIOD = (PONG_WAIT * 6) / 10
- AUTH_TIMEOUT = 5 * time.Second
+ WRITE_WAIT = 30 * time.Second
+ PONG_WAIT = 100 * time.Second
+ PING_PERIOD = (PONG_WAIT * 6) / 10
+ AUTH_TIMEOUT = 5 * time.Second
+ WEBCONN_MEMBER_CACHE_TIME = 1000 * 60 * 30 // 30 minutes
)
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
if len(msg.Broadcast.ChannelId) > 0 {
-
- // 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
+ if model.GetMillis()-webCon.LastAllChannelMembersTime > WEBCONN_MEMBER_CACHE_TIME {
webCon.AllChannelMembers = nil
webCon.LastAllChannelMembersTime = 0
}
diff --git a/app/web_hub.go b/app/web_hub.go
index a50680806..9743d16aa 100644
--- a/app/web_hub.go
+++ b/app/web_hub.go
@@ -278,18 +278,20 @@ func (h *Hub) Start() {
}
case msg := <-h.broadcast:
- for _, webCon := range h.connections {
- if webCon.ShouldSendEvent(msg) {
- select {
- case webCon.Send <- msg:
- default:
- l4g.Error(fmt.Sprintf("webhub.broadcast: cannot send, closing websocket for userId=%v", webCon.UserId))
- close(webCon.Send)
- for i, webConCandidate := range h.connections {
- if webConCandidate == webCon {
- h.connections[i] = h.connections[len(h.connections)-1]
- h.connections = h.connections[:len(h.connections)-1]
- break
+ if OkToSendTypingMessage(msg) {
+ for _, webCon := range h.connections {
+ if webCon.ShouldSendEvent(msg) {
+ select {
+ case webCon.Send <- msg:
+ default:
+ l4g.Error(fmt.Sprintf("webhub.broadcast: cannot send, closing websocket for userId=%v", webCon.UserId))
+ close(webCon.Send)
+ for i, webConCandidate := range h.connections {
+ if webConCandidate == webCon {
+ h.connections[i] = h.connections[len(h.connections)-1]
+ h.connections = h.connections[:len(h.connections)-1]
+ break
+ }
}
}
}
@@ -328,3 +330,14 @@ func (h *Hub) Start() {
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
+}