From ba693f8d5028b62c19f6a730e8dca73a224d0761 Mon Sep 17 00:00:00 2001 From: Vishal Choudhary Date: Wed, 25 May 2022 15:16:54 +0530 Subject: [PATCH] Revert cache changes --- app/usage.go | 2 +- model/cluster_message.go | 1 - model/post.go | 2 -- store/localcachelayer/layer.go | 16 ++------------ store/localcachelayer/post_layer.go | 33 ----------------------------- 5 files changed, 3 insertions(+), 51 deletions(-) diff --git a/app/usage.go b/app/usage.go index 194952b10d6..b0d60e05ee7 100644 --- a/app/usage.go +++ b/app/usage.go @@ -12,7 +12,7 @@ import ( // GetPostsUsage returns "rounded off" total posts count like returns 900 instead of 987 func (a *App) GetPostsUsage() (int64, *model.AppError) { - count, err := a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true, AllowFromCache: true}) + count, err := a.Srv().Store.Post().AnalyticsPostCount(&model.PostCountOptions{ExcludeDeleted: true, UsersPostsOnly: true}) if err != nil { return 0, model.NewAppError("GetPostsUsage", "app.post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) } diff --git a/model/cluster_message.go b/model/cluster_message.go index 35bae0371ec..90999ab03a8 100644 --- a/model/cluster_message.go +++ b/model/cluster_message.go @@ -31,7 +31,6 @@ const ( ClusterEventInvalidateCacheForChannelMemberCounts ClusterEvent = "inv_channel_member_counts" ClusterEventInvalidateCacheForLastPosts ClusterEvent = "inv_last_posts" ClusterEventInvalidateCacheForLastPostTime ClusterEvent = "inv_last_post_time" - ClusterEventInvalidateCacheForPostsUsage ClusterEvent = "inv_posts_usage" ClusterEventInvalidateCacheForTeams ClusterEvent = "inv_teams" ClusterEventClearSessionCacheForAllUsers ClusterEvent = "inv_all_user_sessions" ClusterEventInstallPlugin ClusterEvent = "install_plugin" diff --git a/model/post.go b/model/post.go index f5ae88c759c..740969e2837 100644 --- a/model/post.go +++ b/model/post.go @@ -281,8 +281,6 @@ type PostCountOptions struct { MustHaveHashtag bool ExcludeDeleted bool UsersPostsOnly bool - // AllowFromCache looks up cache only when ExcludeDeleted and UsersPostsOnly are true and rest are falsy. - AllowFromCache bool } func (o *Post) Etag() string { diff --git a/store/localcachelayer/layer.go b/store/localcachelayer/layer.go index 4ebb47180e7..f715c7685ec 100644 --- a/store/localcachelayer/layer.go +++ b/store/localcachelayer/layer.go @@ -41,10 +41,8 @@ const ( ChannelMembersCountsCacheSize = model.ChannelCacheSize ChannelMembersCountsCacheSec = 30 * 60 - LastPostsCacheSize = 20000 - LastPostsCacheSec = 30 * 60 - PostsUsageCacheSize = 1 - PostsUsageCacheSec = 30 * 60 + LastPostsCacheSize = 20000 + LastPostsCacheSec = 30 * 60 TermsOfServiceCacheSize = 20000 TermsOfServiceCacheSec = 30 * 60 @@ -99,7 +97,6 @@ type LocalCacheStore struct { post LocalCachePostStore postLastPostsCache cache.Cache lastPostTimeCache cache.Cache - postsUsageCache cache.Cache user *LocalCacheUserStore userProfileByIdsCache cache.Cache @@ -259,14 +256,6 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf }); err != nil { return } - if localCacheStore.postsUsageCache, err = cacheProvider.NewCache(&cache.CacheOptions{ - Size: PostsUsageCacheSize, - Name: "PostsUsage", - DefaultExpiry: PostsUsageCacheSec * time.Second, - InvalidateClusterEvent: model.ClusterEventInvalidateCacheForPostsUsage, - }); err != nil { - return - } localCacheStore.post = LocalCachePostStore{PostStore: baseStore.Post(), rootStore: &localCacheStore} // TOS @@ -323,7 +312,6 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForSchemes, localCacheStore.scheme.handleClusterInvalidateScheme) cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForFileInfos, localCacheStore.fileInfo.handleClusterInvalidateFileInfo) cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForLastPostTime, localCacheStore.post.handleClusterInvalidateLastPostTime) - cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForPostsUsage, localCacheStore.post.handleClusterInvalidatePostsUsage) cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForWebhooks, localCacheStore.webhook.handleClusterInvalidateWebhook) cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForEmojisById, localCacheStore.emoji.handleClusterInvalidateEmojiById) cluster.RegisterClusterMessageHandler(model.ClusterEventInvalidateCacheForEmojisIdByName, localCacheStore.emoji.handleClusterInvalidateEmojiIdByName) diff --git a/store/localcachelayer/post_layer.go b/store/localcachelayer/post_layer.go index 331367cd0ef..80bc09bdcb5 100644 --- a/store/localcachelayer/post_layer.go +++ b/store/localcachelayer/post_layer.go @@ -34,24 +34,14 @@ func (s *LocalCachePostStore) handleClusterInvalidateLastPosts(msg *model.Cluste } } -func (s *LocalCachePostStore) handleClusterInvalidatePostsUsage(msg *model.ClusterMessage) { - if bytes.Equal(msg.Data, clearCacheMessageData) { - s.rootStore.postsUsageCache.Purge() - } else { - s.rootStore.postsUsageCache.Remove(string(msg.Data)) - } -} - func (s LocalCachePostStore) ClearCaches() { s.rootStore.doClearCacheCluster(s.rootStore.lastPostTimeCache) s.rootStore.doClearCacheCluster(s.rootStore.postLastPostsCache) - s.rootStore.doClearCacheCluster(s.rootStore.postsUsageCache) s.PostStore.ClearCaches() if s.rootStore.metrics != nil { s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Purge") s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Posts Cache - Purge") - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Posts Usage Cache - Purge") } } @@ -141,26 +131,3 @@ func (s LocalCachePostStore) GetPosts(options model.GetPostsOptions, allowFromCa return list, err } - -// AnalyticsPostCount looks up cache only when ExcludeDeleted and UsersPostsOnly are true and rest are falsy. -func (s LocalCachePostStore) AnalyticsPostCount(options *model.PostCountOptions) (int64, error) { - if !options.AllowFromCache || options.MustHaveFile || options.MustHaveHashtag || !options.UsersPostsOnly || !options.ExcludeDeleted || options.TeamId != "" { - return s.PostStore.AnalyticsPostCount(options) - } - - // Currently cache only for app > usage > GetPostsUsage() - // Other filter combinations can be cached if required - cacheKey := "posts_usage" - var count int64 - if err := s.rootStore.doStandardReadCache(s.rootStore.postsUsageCache, cacheKey, &count); err == nil { - return count, nil - } - - count, err := s.PostStore.AnalyticsPostCount(options) - if err != nil { - return 0, err - } - - s.rootStore.doStandardAddToCache(s.rootStore.postsUsageCache, cacheKey, count) - return count, nil -}