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
```
This commit is contained in:
Agniva De Sarker
2024-02-24 11:55:20 +05:30
committed by GitHub
parent 1ae96cefad
commit 401de9b321
3 changed files with 10 additions and 11 deletions
+4 -1
View File
@@ -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
+4 -8
View File
@@ -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
}
+2 -2
View File
@@ -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() {