From 097289f8e473c799ee752aa56e08f605110f5217 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 27 Jan 2017 14:07:34 -0500 Subject: Merge 3.6.2 into master (#5211) * Add webhook cache * Add channel by name cache * Fxing profiles in channels cache * Fix merge --- app/admin.go | 1 + app/channel.go | 19 ++++++++++--------- app/import.go | 2 +- app/notification.go | 6 ------ app/post.go | 6 +++--- app/slackimport.go | 2 +- app/team.go | 2 +- app/web_hub.go | 37 +++++++++++++++++++++++++++++++++---- 8 files changed, 50 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/admin.go b/app/admin.go index 51e69da57..00d60a802 100644 --- a/app/admin.go +++ b/app/admin.go @@ -89,6 +89,7 @@ func InvalidateAllCachesSkipSend() { store.ClearChannelCaches() store.ClearUserCaches() store.ClearPostCaches() + store.ClearWebhookCaches() } func GetConfig() *model.Config { diff --git a/app/channel.go b/app/channel.go index 1844e3177..c9199f829 100644 --- a/app/channel.go +++ b/app/channel.go @@ -88,7 +88,7 @@ func CreateDefaultChannels(teamId string) ([]*model.Channel, *model.AppError) { func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *model.AppError { var err *model.AppError = nil - if result := <-Srv.Store.Channel().GetByName(teamId, "town-square"); result.Err != nil { + if result := <-Srv.Store.Channel().GetByName(teamId, "town-square", true); result.Err != nil { err = result.Err } else { cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, @@ -105,14 +105,14 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m UserId: user.Id, } - InvalidateCacheForChannel(result.Data.(*model.Channel).Id) + InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id) if _, err := CreatePost(post, teamId, false); err != nil { l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err) } } - if result := <-Srv.Store.Channel().GetByName(teamId, "off-topic"); result.Err != nil { + if result := <-Srv.Store.Channel().GetByName(teamId, "off-topic", true); result.Err != nil { err = result.Err } else { cm := &model.ChannelMember{ChannelId: result.Data.(*model.Channel).Id, UserId: user.Id, @@ -129,7 +129,7 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m UserId: user.Id, } - InvalidateCacheForChannel(result.Data.(*model.Channel).Id) + InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id) if _, err := CreatePost(post, teamId, false); err != nil { l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err) @@ -195,7 +195,7 @@ func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { if result := <-Srv.Store.Channel().Update(channel); result.Err != nil { return nil, result.Err } else { - InvalidateCacheForChannel(channel.Id) + InvalidateCacheForChannel(channel) return channel, nil } } @@ -287,6 +287,7 @@ func DeleteChannel(channel *model.Channel, userId string) *model.AppError { if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil { l4g.Error(utils.T("api.channel.delete_channel.incoming_webhook.error"), hook.Id) } + InvalidateCacheForWebhook(hook.Id) } for _, hook := range outgoingHooks { @@ -298,7 +299,7 @@ func DeleteChannel(channel *model.Channel, userId string) *model.AppError { if dresult := <-Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); dresult.Err != nil { return dresult.Err } - InvalidateCacheForChannel(channel.Id) + InvalidateCacheForChannel(channel) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_DELETED, channel.TeamId, "", "", nil) message.Add("channel_id", channel.Id) @@ -351,7 +352,7 @@ func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM } InvalidateCacheForUser(user.Id) - InvalidateCacheForChannel(channel.Id) + InvalidateCacheForChannelMembers(channel.Id) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_ADDED, "", channel.Id, "", nil) message.Add("user_id", user.Id) @@ -508,7 +509,7 @@ func GetChannel(channelId string) (*model.Channel, *model.AppError) { } func GetChannelByName(channelName, teamId string) (*model.Channel, *model.AppError) { - if result := <-Srv.Store.Channel().GetByName(teamId, channelName); result.Err != nil { + if result := <-Srv.Store.Channel().GetByName(teamId, channelName, true); result.Err != nil { return nil, result.Err } else { return result.Data.(*model.Channel), nil @@ -650,7 +651,7 @@ func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel } InvalidateCacheForUser(userIdToRemove) - InvalidateCacheForChannel(channel.Id) + InvalidateCacheForChannelMembers(channel.Id) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_USER_REMOVED, "", channel.Id, "", nil) message.Add("user_id", userIdToRemove) diff --git a/app/import.go b/app/import.go index 882641799..26981f0c2 100644 --- a/app/import.go +++ b/app/import.go @@ -182,7 +182,7 @@ func ImportChannel(data *ChannelImportData, dryRun bool) *model.AppError { } var channel *model.Channel - if result := <-Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, *data.Name); result.Err == nil { + if result := <-Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, *data.Name, true); result.Err == nil { channel = result.Data.(*model.Channel) } else { channel = &model.Channel{} diff --git a/app/notification.go b/app/notification.go index c65635f60..9ad0b346b 100644 --- a/app/notification.go +++ b/app/notification.go @@ -35,12 +35,6 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe profileMap = result.Data.(map[string]*model.User) } - // If the user who made the post isn't in the channel, don't send a notification - if _, ok := profileMap[post.UserId]; !ok && post.Props["from_webhook"] != "true" { - l4g.Debug(utils.T("api.post.send_notifications.user_id.debug"), post.Id, channel.Id, post.UserId) - return []string{}, nil - } - mentionedUserIds := make(map[string]bool) allActivityPushUserIds := []string{} hereNotification := false diff --git a/app/post.go b/app/post.go index 6d34cc035..d7bc2cf71 100644 --- a/app/post.go +++ b/app/post.go @@ -110,9 +110,6 @@ func CreatePost(post *model.Post, teamId string, triggerWebhooks bool) (*model.P } } - InvalidateCacheForChannel(rpost.ChannelId) - InvalidateCacheForChannelPosts(rpost.ChannelId) - if err := handlePostEvents(rpost, teamId, triggerWebhooks); err != nil { return nil, err } @@ -139,6 +136,9 @@ func handlePostEvents(post *model.Post, teamId string, triggerWebhooks bool) *mo channel = result.Data.(*model.Channel) } + InvalidateCacheForChannel(channel) + InvalidateCacheForChannelPosts(channel.Id) + var user *model.User if result := <-uchan; result.Err != nil { return result.Err diff --git a/app/slackimport.go b/app/slackimport.go index edeb601e2..3289f140e 100644 --- a/app/slackimport.go +++ b/app/slackimport.go @@ -472,7 +472,7 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str newChannel = SlackSanitiseChannelProperties(newChannel) var mChannel *model.Channel - if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err == nil { + if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name, true); result.Err == nil { // The channel already exists as an active channel. Merge with the existing one. mChannel = result.Data.(*model.Channel) log.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName})) diff --git a/app/team.go b/app/team.go index aabdc0bfd..3c7145818 100644 --- a/app/team.go +++ b/app/team.go @@ -408,7 +408,7 @@ func LeaveTeam(team *model.Team, user *model.User) *model.AppError { for _, channel := range *channelList { if channel.Type != model.CHANNEL_DIRECT { - InvalidateCacheForChannel(channel.Id) + InvalidateCacheForChannelMembers(channel.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 28d2c0095..c8fbfbc34 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -103,18 +103,35 @@ func PublishSkipClusterSend(message *model.WebSocketEvent) { } } -func InvalidateCacheForChannel(channelId string) { - InvalidateCacheForChannelSkipClusterSend(channelId) +func InvalidateCacheForChannel(channel *model.Channel) { + InvalidateCacheForChannelSkipClusterSend(channel.Id) + InvalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name) if cluster := einterfaces.GetClusterInterface(); cluster != nil { - cluster.InvalidateCacheForChannel(channelId) + cluster.InvalidateCacheForChannel(channel.Id) + cluster.InvalidateCacheForChannelByName(channel.TeamId, channel.Name) + } +} + +func InvalidateCacheForChannelMembers(channelId string) { + InvalidateCacheForChannelMembersSkipClusterSend(channelId) + + if cluster := einterfaces.GetClusterInterface(); cluster != nil { + cluster.InvalidateCacheForChannelMembers(channelId) } } func InvalidateCacheForChannelSkipClusterSend(channelId string) { + Srv.Store.Channel().InvalidateChannel(channelId) +} + +func InvalidateCacheForChannelMembersSkipClusterSend(channelId string) { Srv.Store.User().InvalidateProfilesInChannelCache(channelId) Srv.Store.Channel().InvalidateMemberCount(channelId) - Srv.Store.Channel().InvalidateChannel(channelId) +} + +func InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string) { + Srv.Store.Channel().InvalidateChannelByName(teamId, name) } func InvalidateCacheForChannelPosts(channelId string) { @@ -147,6 +164,18 @@ func InvalidateCacheForUserSkipClusterSend(userId string) { } } +func InvalidateCacheForWebhook(webhookId string) { + InvalidateCacheForWebhookSkipClusterSend(webhookId) + + if cluster := einterfaces.GetClusterInterface(); cluster != nil { + cluster.InvalidateCacheForWebhook(webhookId) + } +} + +func InvalidateCacheForWebhookSkipClusterSend(webhookId string) { + Srv.Store.Webhook().InvalidateWebhookCache(webhookId) +} + func InvalidateWebConnSessionCacheForUser(userId string) { if len(hubs) != 0 { GetHubForUserId(userId).InvalidateUser(userId) -- cgit v1.2.3-1-g7c22