summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-02-24 09:15:36 -0500
committerCorey Hulen <corey@hulen.com>2017-02-24 09:15:36 -0500
commitba028ed74b69bd1dd902344663fbf8ba4f1dfb87 (patch)
tree773fb0cf301208023a50803f21ebbecf64466a4f /app
parent7fc5dc236aa2437e81b238f65d39c2f795eac493 (diff)
downloadchat-ba028ed74b69bd1dd902344663fbf8ba4f1dfb87.tar.gz
chat-ba028ed74b69bd1dd902344663fbf8ba4f1dfb87.tar.bz2
chat-ba028ed74b69bd1dd902344663fbf8ba4f1dfb87.zip
Adding caching to get channel member (#5518)
Diffstat (limited to 'app')
-rw-r--r--app/channel.go11
-rw-r--r--app/team.go1
-rw-r--r--app/web_hub.go12
3 files changed, 20 insertions, 4 deletions
diff --git a/app/channel.go b/app/channel.go
index fb4198c37..cff9564b5 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -175,7 +175,7 @@ func WaitForChannelMembership(channelId string, userId string) {
time.Sleep(100 * time.Millisecond)
- result := <-Srv.Store.Channel().GetMember(channelId, userId)
+ result := <-Srv.Store.Channel().GetMember(channelId, userId, true)
// If the membership was found then return
if result.Err == nil {
@@ -214,6 +214,7 @@ func UpdateChannelMemberRoles(channelId string, userId string, newRoles string)
return nil, result.Err
}
+ InvalidateCacheForChannelMember(channelId, userId)
InvalidateCacheForUser(userId)
return member, nil
}
@@ -245,6 +246,7 @@ func UpdateChannelMemberNotifyProps(data map[string]string, channelId string, us
if result := <-Srv.Store.Channel().UpdateMember(member); result.Err != nil {
return nil, result.Err
} else {
+ InvalidateCacheForChannelMember(channelId, userId)
InvalidateCacheForUser(userId)
InvalidateCacheForChannelMembersNotifyProps(channelId)
return member, nil
@@ -333,7 +335,7 @@ func addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
}
tmchan := Srv.Store.Team().GetMember(channel.TeamId, user.Id)
- cmchan := Srv.Store.Channel().GetMember(channel.Id, user.Id)
+ cmchan := Srv.Store.Channel().GetMember(channel.Id, user.Id, true)
if result := <-tmchan; result.Err != nil {
return nil, result.Err
@@ -588,7 +590,7 @@ func GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (
}
func GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
- if result := <-Srv.Store.Channel().GetMember(channelId, userId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetMember(channelId, userId, true); result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.ChannelMember), nil
@@ -637,7 +639,7 @@ func GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *mode
func JoinChannel(channel *model.Channel, userId string) *model.AppError {
userChan := Srv.Store.User().Get(userId)
- memberChan := Srv.Store.Channel().GetMember(channel.Id, userId)
+ memberChan := Srv.Store.Channel().GetMember(channel.Id, userId, true)
if uresult := <-userChan; uresult.Err != nil {
return uresult.Err
@@ -790,6 +792,7 @@ func removeUserFromChannel(userIdToRemove string, removerUserId string, channel
}
InvalidateCacheForUser(userIdToRemove)
+ InvalidateCacheForChannelMember(channel.Id, userIdToRemove)
InvalidateCacheForChannelMembers(channel.Id)
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_REMOVED, "", channel.Id, "", nil)
diff --git a/app/team.go b/app/team.go
index 0c0a6a4da..ce5e107ba 100644
--- a/app/team.go
+++ b/app/team.go
@@ -424,6 +424,7 @@ func LeaveTeam(team *model.Team, user *model.User) *model.AppError {
for _, channel := range *channelList {
if channel.Type != model.CHANNEL_DIRECT {
InvalidateCacheForChannelMembers(channel.Id)
+ InvalidateCacheForChannelMember(channel.Id, user.Id)
if result := <-Srv.Store.Channel().RemoveMember(channel.Id, user.Id); result.Err != nil {
return result.Err
}
diff --git a/app/web_hub.go b/app/web_hub.go
index a214ffb5e..13852e8eb 100644
--- a/app/web_hub.go
+++ b/app/web_hub.go
@@ -170,6 +170,18 @@ func InvalidateCacheForUser(userId string) {
}
}
+func InvalidateCacheForChannelMember(channelId string, userId string) {
+ InvalidateCacheForChannelMemberSkipClusterSend(channelId, userId)
+
+ if einterfaces.GetClusterInterface() != nil {
+ einterfaces.GetClusterInterface().InvalidateCacheForChannelMember(channelId, userId)
+ }
+}
+
+func InvalidateCacheForChannelMemberSkipClusterSend(channelId string, userId string) {
+ Srv.Store.Channel().InvalidateMember(channelId, userId)
+}
+
func InvalidateCacheForUserSkipClusterSend(userId string) {
Srv.Store.Channel().InvalidateAllChannelMembersForUser(userId)
Srv.Store.User().InvalidateProfilesInChannelCacheByUser(userId)