@@ -19,7 +19,7 @@ const (
|
||||
)
|
||||
|
||||
type webConnActivityMessage struct {
|
||||
userId string
|
||||
userID string
|
||||
sessionToken string
|
||||
activityAt int64
|
||||
}
|
||||
@@ -30,7 +30,7 @@ type webConnDirectMessage struct {
|
||||
}
|
||||
|
||||
type webConnSessionMessage struct {
|
||||
userId string
|
||||
userID string
|
||||
sessionToken string
|
||||
isRegistered chan bool
|
||||
}
|
||||
@@ -94,19 +94,19 @@ func (a *App) HubStart() {
|
||||
a.srv.hubs = hubs
|
||||
}
|
||||
|
||||
func (a *App) invalidateCacheForUserSkipClusterSend(userId string) {
|
||||
a.Srv().Store.Channel().InvalidateAllChannelMembersForUser(userId)
|
||||
a.InvalidateWebConnSessionCacheForUser(userId)
|
||||
func (a *App) invalidateCacheForUserSkipClusterSend(userID string) {
|
||||
a.Srv().Store.Channel().InvalidateAllChannelMembersForUser(userID)
|
||||
a.InvalidateWebConnSessionCacheForUser(userID)
|
||||
}
|
||||
|
||||
func (a *App) invalidateCacheForWebhook(webhookId string) {
|
||||
a.Srv().Store.Webhook().InvalidateWebhookCache(webhookId)
|
||||
func (a *App) invalidateCacheForWebhook(webhookID string) {
|
||||
a.Srv().Store.Webhook().InvalidateWebhookCache(webhookID)
|
||||
}
|
||||
|
||||
func (a *App) InvalidateWebConnSessionCacheForUser(userId string) {
|
||||
hub := a.GetHubForUserId(userId)
|
||||
func (a *App) InvalidateWebConnSessionCacheForUser(userID string) {
|
||||
hub := a.GetHubForUserId(userID)
|
||||
if hub != nil {
|
||||
hub.InvalidateUser(userId)
|
||||
hub.InvalidateUser(userID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,20 +124,20 @@ func (a *App) HubStop() {
|
||||
}
|
||||
|
||||
// GetHubForUserId returns the hub for a given user id.
|
||||
func (s *Server) GetHubForUserId(userId string) *Hub {
|
||||
// TODO: check if caching the userId -> hub mapping
|
||||
func (s *Server) GetHubForUserId(userID string) *Hub {
|
||||
// TODO: check if caching the userID -> hub mapping
|
||||
// is worth the memory tradeoff.
|
||||
// https://mattermost.atlassian.net/browse/MM-26629.
|
||||
var hash maphash.Hash
|
||||
hash.SetSeed(s.hashSeed)
|
||||
hash.Write([]byte(userId))
|
||||
hash.Write([]byte(userID))
|
||||
index := hash.Sum64() % uint64(len(s.hubs))
|
||||
|
||||
return s.hubs[int(index)]
|
||||
}
|
||||
|
||||
func (a *App) GetHubForUserId(userId string) *Hub {
|
||||
return a.Srv().GetHubForUserId(userId)
|
||||
func (a *App) GetHubForUserId(userID string) *Hub {
|
||||
return a.Srv().GetHubForUserId(userID)
|
||||
}
|
||||
|
||||
// HubRegister registers a connection to a hub.
|
||||
@@ -254,12 +254,12 @@ func (a *App) invalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channel
|
||||
a.Srv().Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelId)
|
||||
}
|
||||
|
||||
func (a *App) invalidateCacheForChannelByNameSkipClusterSend(teamId, name string) {
|
||||
if teamId == "" {
|
||||
teamId = "dm"
|
||||
func (a *App) invalidateCacheForChannelByNameSkipClusterSend(teamID, name string) {
|
||||
if teamID == "" {
|
||||
teamID = "dm"
|
||||
}
|
||||
|
||||
a.Srv().Store.Channel().InvalidateChannelByName(teamId, name)
|
||||
a.Srv().Store.Channel().InvalidateChannelByName(teamID, name)
|
||||
}
|
||||
|
||||
func (a *App) invalidateCacheForChannelPosts(channelId string) {
|
||||
@@ -267,31 +267,31 @@ func (a *App) invalidateCacheForChannelPosts(channelId string) {
|
||||
a.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
}
|
||||
|
||||
func (a *App) InvalidateCacheForUser(userId string) {
|
||||
a.invalidateCacheForUserSkipClusterSend(userId)
|
||||
func (a *App) InvalidateCacheForUser(userID string) {
|
||||
a.invalidateCacheForUserSkipClusterSend(userID)
|
||||
|
||||
a.Srv().Store.User().InvalidateProfilesInChannelCacheByUser(userId)
|
||||
a.Srv().Store.User().InvalidateProfileCacheForUser(userId)
|
||||
a.Srv().Store.User().InvalidateProfilesInChannelCacheByUser(userID)
|
||||
a.Srv().Store.User().InvalidateProfileCacheForUser(userID)
|
||||
|
||||
if a.Cluster() != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: userId,
|
||||
Data: userID,
|
||||
}
|
||||
a.Cluster().SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) invalidateCacheForUserTeams(userId string) {
|
||||
a.InvalidateWebConnSessionCacheForUser(userId)
|
||||
a.Srv().Store.Team().InvalidateAllTeamIdsForUser(userId)
|
||||
func (a *App) invalidateCacheForUserTeams(userID string) {
|
||||
a.InvalidateWebConnSessionCacheForUser(userID)
|
||||
a.Srv().Store.Team().InvalidateAllTeamIdsForUser(userID)
|
||||
|
||||
if a.Cluster() != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER_TEAMS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: userId,
|
||||
Data: userID,
|
||||
}
|
||||
a.Cluster().SendClusterMessage(msg)
|
||||
}
|
||||
@@ -331,9 +331,9 @@ func (h *Hub) Unregister(webConn *WebConn) {
|
||||
}
|
||||
|
||||
// Determines if a user's session is registered a connection from the hub.
|
||||
func (h *Hub) IsRegistered(userId, sessionToken string) bool {
|
||||
func (h *Hub) IsRegistered(userID, sessionToken string) bool {
|
||||
ws := &webConnSessionMessage{
|
||||
userId: userId,
|
||||
userID: userID,
|
||||
sessionToken: sessionToken,
|
||||
isRegistered: make(chan bool),
|
||||
}
|
||||
@@ -366,19 +366,19 @@ func (h *Hub) Broadcast(message *model.WebSocketEvent) {
|
||||
}
|
||||
|
||||
// InvalidateUser invalidates the cache for the given user.
|
||||
func (h *Hub) InvalidateUser(userId string) {
|
||||
func (h *Hub) InvalidateUser(userID string) {
|
||||
select {
|
||||
case h.invalidateUser <- userId:
|
||||
case h.invalidateUser <- userID:
|
||||
case <-h.stop:
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateActivity sets the LastUserActivityAt field for the connection
|
||||
// of the user.
|
||||
func (h *Hub) UpdateActivity(userId, sessionToken string, activityAt int64) {
|
||||
func (h *Hub) UpdateActivity(userID, sessionToken string, activityAt int64) {
|
||||
select {
|
||||
case h.activity <- &webConnActivityMessage{
|
||||
userId: userId,
|
||||
userID: userID,
|
||||
sessionToken: sessionToken,
|
||||
activityAt: activityAt,
|
||||
}:
|
||||
@@ -417,7 +417,7 @@ func (h *Hub) Start() {
|
||||
for {
|
||||
select {
|
||||
case webSessionMessage := <-h.checkRegistered:
|
||||
conns := connIndex.ForUser(webSessionMessage.userId)
|
||||
conns := connIndex.ForUser(webSessionMessage.userID)
|
||||
var isRegistered bool
|
||||
for _, conn := range conns {
|
||||
if conn.GetSessionToken() == webSessionMessage.sessionToken {
|
||||
@@ -458,12 +458,12 @@ func (h *Hub) Start() {
|
||||
h.app.SetStatusLastActivityAt(webConn.UserId, latestActivity)
|
||||
})
|
||||
}
|
||||
case userId := <-h.invalidateUser:
|
||||
for _, webConn := range connIndex.ForUser(userId) {
|
||||
case userID := <-h.invalidateUser:
|
||||
for _, webConn := range connIndex.ForUser(userID) {
|
||||
webConn.InvalidateCache()
|
||||
}
|
||||
case activity := <-h.activity:
|
||||
for _, webConn := range connIndex.ForUser(activity.userId) {
|
||||
for _, webConn := range connIndex.ForUser(activity.userID) {
|
||||
if webConn.GetSessionToken() == activity.sessionToken {
|
||||
webConn.lastUserActivityAt = activity.activityAt
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user