Adding session cache directly to web-conn (#4861)

Этот коммит содержится в:
Christopher Speller
2016-12-22 07:52:02 -05:00
коммит произвёл Joram Wilander
родитель 64a86bd32f
Коммит c434e84114
4 изменённых файлов: 34 добавлений и 15 удалений

Просмотреть файл

@@ -566,6 +566,8 @@ func RemoveAllSessionsForUserIdSkipClusterSend(userId string) {
} }
} }
InvalidateWebConnSessionCacheForUser(userId)
} }
func AddSessionToCache(session *model.Session) { func AddSessionToCache(session *model.Session) {

Просмотреть файл

@@ -705,7 +705,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
} }
if userAllowsEmails && status.Status != model.STATUS_ONLINE { if userAllowsEmails && status.Status != model.STATUS_ONLINE {
go sendNotificationEmail(c, post, profileMap[id], channel, team, senderName[id], sender) sendNotificationEmail(c, post, profileMap[id], channel, team, senderName[id], sender)
} }
} }
} }
@@ -801,7 +801,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
} }
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
go sendPushNotification(post, profileMap[id], channel, senderName[id], true) sendPushNotification(post, profileMap[id], channel, senderName[id], true)
} }
} }
@@ -814,7 +814,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
} }
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
go sendPushNotification(post, profileMap[id], channel, senderName[id], false) sendPushNotification(post, profileMap[id], channel, senderName[id], false)
} }
} }
} }

Просмотреть файл

@@ -27,6 +27,7 @@ type WebConn struct {
WebSocket *websocket.Conn WebSocket *websocket.Conn
Send chan model.WebSocketMessage Send chan model.WebSocketMessage
SessionToken string SessionToken string
SessionExpiresAt int64
UserId string UserId string
T goi18n.TranslateFunc T goi18n.TranslateFunc
Locale string Locale string
@@ -40,12 +41,13 @@ func NewWebConn(c *Context, ws *websocket.Conn) *WebConn {
} }
return &WebConn{ return &WebConn{
Send: make(chan model.WebSocketMessage, 256), Send: make(chan model.WebSocketMessage, 256),
WebSocket: ws, WebSocket: ws,
UserId: c.Session.UserId, UserId: c.Session.UserId,
SessionToken: c.Session.Token, SessionToken: c.Session.Token,
T: c.T, SessionExpiresAt: c.Session.ExpiresAt,
Locale: c.Locale, T: c.T,
Locale: c.Locale,
} }
} }
@@ -144,16 +146,25 @@ func (c *WebConn) writePump() {
func (webCon *WebConn) InvalidateCache() { func (webCon *WebConn) InvalidateCache() {
webCon.AllChannelMembers = nil webCon.AllChannelMembers = nil
webCon.LastAllChannelMembersTime = 0 webCon.LastAllChannelMembersTime = 0
webCon.SessionExpiresAt = 0
} }
func (webCon *WebConn) isAuthenticated() bool { func (webCon *WebConn) isAuthenticated() bool {
if webCon.SessionToken == "" { // Check the expiry to see if we need to check for a new session
return false if webCon.SessionExpiresAt < model.GetMillis() {
} if webCon.SessionToken == "" {
return false
}
session := GetSession(webCon.SessionToken) session := GetSession(webCon.SessionToken)
if session == nil || session.IsExpired() { if session == nil || session.IsExpired() {
return false webCon.SessionToken = ""
webCon.SessionExpiresAt = 0
return false
}
webCon.SessionToken = session.Token
webCon.SessionExpiresAt = session.ExpiresAt
} }
return true return true

Просмотреть файл

@@ -145,6 +145,12 @@ func InvalidateCacheForUserSkipClusterSend(userId string) {
} }
} }
func InvalidateWebConnSessionCacheForUser(userId string) {
if len(hubs) != 0 {
GetHubForUserId(userId).InvalidateUser(userId)
}
}
func (h *Hub) Register(webConn *WebConn) { func (h *Hub) Register(webConn *WebConn) {
h.register <- webConn h.register <- webConn