From 401de9b3218dc6c6350216d3834e1f2132444fde Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 24 Feb 2024 11:55:20 +0530 Subject: [PATCH] MM-56925: Fix unnecessary cache invalidation of pinned post count (#26264) invalidateCacheForChannelPosts invalidated the pinned post count and the lastPostTime cache. But not all endpoints actually pins or unpins the post. That's only possible via the UpdatePost or PatchPost methods. Therefore, we remove the unnecessary cache invalidation. This is also important because this gets called for every single channel load, and every new post would invalidate this cache. https://mattermost.atlassian.net/browse/MM-56925 ```release-note NONE ``` --- server/channels/app/post.go | 5 ++++- server/channels/app/post_acknowledgements.go | 12 ++++-------- server/channels/app/reaction.go | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/server/channels/app/post.go b/server/channels/app/post.go index 2bb98a5b4a..3def93614a 100644 --- a/server/channels/app/post.go +++ b/server/channels/app/post.go @@ -489,7 +489,10 @@ func (a *App) handlePostEvents(c request.CTX, post *model.Post, user *model.User } a.Srv().Platform().InvalidateCacheForChannel(channel) - a.invalidateCacheForChannelPosts(channel.Id) + if post.IsPinned { + a.Srv().Store().Channel().InvalidatePinnedPostCount(channel.Id) + } + a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id) if _, err := a.SendNotifications(c, post, team, channel, user, parentPostList, setOnline); err != nil { return err diff --git a/server/channels/app/post_acknowledgements.go b/server/channels/app/post_acknowledgements.go index 0ca509ef9d..d5c9f755f0 100644 --- a/server/channels/app/post_acknowledgements.go +++ b/server/channels/app/post_acknowledgements.go @@ -46,11 +46,9 @@ func (a *App) SaveAcknowledgementForPost(c request.CTX, postID, userID string) ( } // The post is always modified since the UpdateAt always changes - a.invalidateCacheForChannelPosts(channel.Id) + a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id) - a.Srv().Go(func() { - a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementAdded, acknowledgement, post) - }) + a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementAdded, acknowledgement, post) return acknowledgement, nil } @@ -92,11 +90,9 @@ func (a *App) DeleteAcknowledgementForPost(c request.CTX, postID, userID string) } // The post is always modified since the UpdateAt always changes - a.invalidateCacheForChannelPosts(channel.Id) + a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id) - a.Srv().Go(func() { - a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementRemoved, oldAck, post) - }) + a.sendAcknowledgementEvent(model.WebsocketEventAcknowledgementRemoved, oldAck, post) return nil } diff --git a/server/channels/app/reaction.go b/server/channels/app/reaction.go index 449ed3aab8..2a46fda2af 100644 --- a/server/channels/app/reaction.go +++ b/server/channels/app/reaction.go @@ -71,7 +71,7 @@ func (a *App) SaveReactionForPost(c request.CTX, reaction *model.Reaction) (*mod } // The post is always modified since the UpdateAt always changes - a.invalidateCacheForChannelPosts(post.ChannelId) + a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id) pluginContext := pluginContext(c) a.Srv().Go(func() { @@ -144,7 +144,7 @@ func (a *App) DeleteReactionForPost(c request.CTX, reaction *model.Reaction) *mo } // The post is always modified since the UpdateAt always changes - a.invalidateCacheForChannelPosts(post.ChannelId) + a.Srv().Store().Post().InvalidateLastPostTimeCache(channel.Id) pluginContext := pluginContext(c) a.Srv().Go(func() {