[GH-13105] Migrate channelPinnedPostCountsCache cache from store/sqlstore/channel_store.go to the new store/localcachelayer (#13164)
* Migrate channelPinnedPostCountsCache cache from store/sqlstore/channel_store.go to the new store/localcachelayer * Remove GetPinnedPostCountFromCache * Rearrange test to avoid undeclared variable
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
070ec77ee3
Коммит
d2e78e28a9
@@ -29,6 +29,7 @@ const (
|
|||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOKS = "inv_webhooks"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOKS = "inv_webhooks"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID = "inv_emojis_by_id"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID = "inv_emojis_by_id"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME = "inv_emojis_id_by_name"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME = "inv_emojis_id_by_name"
|
||||||
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_PINNEDPOSTS_COUNTS = "inv_channel_pinnedposts_counts"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS = "inv_channel_member_counts"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS = "inv_channel_member_counts"
|
||||||
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POSTS = "inv_last_posts"
|
CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POSTS = "inv_last_posts"
|
||||||
CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_ALL_USERS = "inv_all_user_sessions"
|
CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_ALL_USERS = "inv_all_user_sessions"
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ func (s *LocalCacheChannelStore) handleClusterInvalidateChannelMemberCounts(msg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelPinnedPostCount(msg *model.ClusterMessage) {
|
||||||
|
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||||
|
s.rootStore.channelPinnedPostCountsCache.Purge()
|
||||||
|
} else {
|
||||||
|
s.rootStore.channelPinnedPostCountsCache.Remove(msg.Data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelGuestCounts(msg *model.ClusterMessage) {
|
func (s *LocalCacheChannelStore) handleClusterInvalidateChannelGuestCounts(msg *model.ClusterMessage) {
|
||||||
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
||||||
s.rootStore.channelGuestCountCache.Purge()
|
s.rootStore.channelGuestCountCache.Purge()
|
||||||
@@ -31,14 +39,23 @@ func (s *LocalCacheChannelStore) handleClusterInvalidateChannelGuestCounts(msg *
|
|||||||
|
|
||||||
func (s LocalCacheChannelStore) ClearCaches() {
|
func (s LocalCacheChannelStore) ClearCaches() {
|
||||||
s.rootStore.doClearCacheCluster(s.rootStore.channelMemberCountsCache)
|
s.rootStore.doClearCacheCluster(s.rootStore.channelMemberCountsCache)
|
||||||
|
s.rootStore.doClearCacheCluster(s.rootStore.channelPinnedPostCountsCache)
|
||||||
s.rootStore.doClearCacheCluster(s.rootStore.channelGuestCountCache)
|
s.rootStore.doClearCacheCluster(s.rootStore.channelGuestCountCache)
|
||||||
s.ChannelStore.ClearCaches()
|
s.ChannelStore.ClearCaches()
|
||||||
if s.rootStore.metrics != nil {
|
if s.rootStore.metrics != nil {
|
||||||
|
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Pinned Post Counts - Purge")
|
||||||
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Purge")
|
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Purge")
|
||||||
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Guest Count - Purge")
|
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Guest Count - Purge")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s LocalCacheChannelStore) InvalidatePinnedPostCount(channelId string) {
|
||||||
|
s.rootStore.doInvalidateCacheCluster(s.rootStore.channelPinnedPostCountsCache, channelId)
|
||||||
|
if s.rootStore.metrics != nil {
|
||||||
|
s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Pinned Post Counts - Remove by ChannelId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s LocalCacheChannelStore) InvalidateMemberCount(channelId string) {
|
func (s LocalCacheChannelStore) InvalidateMemberCount(channelId string) {
|
||||||
s.rootStore.doInvalidateCacheCluster(s.rootStore.channelMemberCountsCache, channelId)
|
s.rootStore.doInvalidateCacheCluster(s.rootStore.channelMemberCountsCache, channelId)
|
||||||
if s.rootStore.metrics != nil {
|
if s.rootStore.metrics != nil {
|
||||||
@@ -95,3 +112,23 @@ func (s LocalCacheChannelStore) GetMemberCountFromCache(channelId string) int64
|
|||||||
|
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s LocalCacheChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) {
|
||||||
|
if allowFromCache {
|
||||||
|
if count := s.rootStore.doStandardReadCache(s.rootStore.channelPinnedPostCountsCache, channelId); count != nil {
|
||||||
|
return count.(int64), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if allowFromCache {
|
||||||
|
s.rootStore.doStandardAddToCache(s.rootStore.channelPinnedPostCountsCache, channelId, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -88,6 +88,68 @@ func TestChannelStoreChannelMemberCountsCache(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChannelStoreChannelPinnedPostsCountsCache(t *testing.T) {
|
||||||
|
countResult := int64(10)
|
||||||
|
|
||||||
|
t.Run("first call not cached, second cached and returning same data", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore()
|
||||||
|
cachedStore := NewLocalCacheLayer(mockStore, nil, nil)
|
||||||
|
|
||||||
|
count, err := cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Equal(t, count, countResult)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
count, err = cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.Equal(t, count, countResult)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("first call not cached, second force no cached", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore()
|
||||||
|
cachedStore := NewLocalCacheLayer(mockStore, nil, nil)
|
||||||
|
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", false)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("first call force no cached, second not cached, third cached", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore()
|
||||||
|
cachedStore := NewLocalCacheLayer(mockStore, nil, nil)
|
||||||
|
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", false)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 2)
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("first call not cached, clear cache, second call not cached", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore()
|
||||||
|
cachedStore := NewLocalCacheLayer(mockStore, nil, nil)
|
||||||
|
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
cachedStore.Channel().ClearCaches()
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("first call not cached, invalidate cache, second call not cached", func(t *testing.T) {
|
||||||
|
mockStore := getMockStore()
|
||||||
|
cachedStore := NewLocalCacheLayer(mockStore, nil, nil)
|
||||||
|
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 1)
|
||||||
|
cachedStore.Channel().InvalidatePinnedPostCount("id")
|
||||||
|
cachedStore.Channel().GetPinnedPostCount("id", true)
|
||||||
|
mockStore.Channel().(*mocks.ChannelStore).AssertNumberOfCalls(t, "GetPinnedPostCount", 2)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestChannelStoreGuestCountCache(t *testing.T) {
|
func TestChannelStoreGuestCountCache(t *testing.T) {
|
||||||
countResult := int64(12)
|
countResult := int64(12)
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ const (
|
|||||||
EMOJI_CACHE_SIZE = 5000
|
EMOJI_CACHE_SIZE = 5000
|
||||||
EMOJI_CACHE_SEC = 30 * 60
|
EMOJI_CACHE_SEC = 30 * 60
|
||||||
|
|
||||||
|
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||||
|
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC = 30 * 60
|
||||||
|
|
||||||
CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||||
CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 30 * 60
|
CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 30 * 60
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ type LocalCacheStore struct {
|
|||||||
channel LocalCacheChannelStore
|
channel LocalCacheChannelStore
|
||||||
channelMemberCountsCache *utils.Cache
|
channelMemberCountsCache *utils.Cache
|
||||||
channelGuestCountCache *utils.Cache
|
channelGuestCountCache *utils.Cache
|
||||||
|
channelPinnedPostCountsCache *utils.Cache
|
||||||
webhook LocalCacheWebhookStore
|
webhook LocalCacheWebhookStore
|
||||||
webhookCache *utils.Cache
|
webhookCache *utils.Cache
|
||||||
post LocalCachePostStore
|
post LocalCachePostStore
|
||||||
@@ -82,6 +86,7 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
|||||||
localCacheStore.emojiCacheById = utils.NewLruWithParams(EMOJI_CACHE_SIZE, "EmojiById", EMOJI_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID)
|
localCacheStore.emojiCacheById = utils.NewLruWithParams(EMOJI_CACHE_SIZE, "EmojiById", EMOJI_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID)
|
||||||
localCacheStore.emojiIdCacheByName = utils.NewLruWithParams(EMOJI_CACHE_SIZE, "EmojiByName", EMOJI_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME)
|
localCacheStore.emojiIdCacheByName = utils.NewLruWithParams(EMOJI_CACHE_SIZE, "EmojiByName", EMOJI_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME)
|
||||||
localCacheStore.emoji = LocalCacheEmojiStore{EmojiStore: baseStore.Emoji(), rootStore: &localCacheStore}
|
localCacheStore.emoji = LocalCacheEmojiStore{EmojiStore: baseStore.Emoji(), rootStore: &localCacheStore}
|
||||||
|
localCacheStore.channelPinnedPostCountsCache = utils.NewLruWithParams(CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE, "ChannelPinnedPostsCounts", CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_PINNEDPOSTS_COUNTS)
|
||||||
localCacheStore.channelMemberCountsCache = utils.NewLruWithParams(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE, "ChannelMemberCounts", CHANNEL_MEMBERS_COUNTS_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS)
|
localCacheStore.channelMemberCountsCache = utils.NewLruWithParams(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE, "ChannelMemberCounts", CHANNEL_MEMBERS_COUNTS_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS)
|
||||||
localCacheStore.channelGuestCountCache = utils.NewLruWithParams(CHANNEL_GUEST_COUNT_CACHE_SIZE, "ChannelGuestsCount", CHANNEL_GUEST_COUNT_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_GUEST_COUNT)
|
localCacheStore.channelGuestCountCache = utils.NewLruWithParams(CHANNEL_GUEST_COUNT_CACHE_SIZE, "ChannelGuestsCount", CHANNEL_GUEST_COUNT_CACHE_SEC, model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_GUEST_COUNT)
|
||||||
localCacheStore.channel = LocalCacheChannelStore{ChannelStore: baseStore.Channel(), rootStore: &localCacheStore}
|
localCacheStore.channel = LocalCacheChannelStore{ChannelStore: baseStore.Channel(), rootStore: &localCacheStore}
|
||||||
@@ -97,6 +102,7 @@ func NewLocalCacheLayer(baseStore store.Store, metrics einterfaces.MetricsInterf
|
|||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOKS, localCacheStore.webhook.handleClusterInvalidateWebhook)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOKS, localCacheStore.webhook.handleClusterInvalidateWebhook)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID, localCacheStore.emoji.handleClusterInvalidateEmojiById)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_BY_ID, localCacheStore.emoji.handleClusterInvalidateEmojiById)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME, localCacheStore.emoji.handleClusterInvalidateEmojiIdByName)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_EMOJIS_ID_BY_NAME, localCacheStore.emoji.handleClusterInvalidateEmojiIdByName)
|
||||||
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_PINNEDPOSTS_COUNTS, localCacheStore.channel.handleClusterInvalidateChannelPinnedPostCount)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS, localCacheStore.channel.handleClusterInvalidateChannelMemberCounts)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBER_COUNTS, localCacheStore.channel.handleClusterInvalidateChannelMemberCounts)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_GUEST_COUNT, localCacheStore.channel.handleClusterInvalidateChannelGuestCounts)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_GUEST_COUNT, localCacheStore.channel.handleClusterInvalidateChannelGuestCounts)
|
||||||
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POSTS, localCacheStore.post.handleClusterInvalidateLastPosts)
|
cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_LAST_POSTS, localCacheStore.post.handleClusterInvalidateLastPosts)
|
||||||
@@ -191,6 +197,7 @@ func (s *LocalCacheStore) Invalidate() {
|
|||||||
s.doClearCacheCluster(s.emojiCacheById)
|
s.doClearCacheCluster(s.emojiCacheById)
|
||||||
s.doClearCacheCluster(s.emojiIdCacheByName)
|
s.doClearCacheCluster(s.emojiIdCacheByName)
|
||||||
s.doClearCacheCluster(s.channelMemberCountsCache)
|
s.doClearCacheCluster(s.channelMemberCountsCache)
|
||||||
|
s.doClearCacheCluster(s.channelPinnedPostCountsCache)
|
||||||
s.doClearCacheCluster(s.channelGuestCountCache)
|
s.doClearCacheCluster(s.channelGuestCountCache)
|
||||||
s.doClearCacheCluster(s.postLastPostsCache)
|
s.doClearCacheCluster(s.postLastPostsCache)
|
||||||
s.doClearCacheCluster(s.userProfileByIdsCache)
|
s.doClearCacheCluster(s.userProfileByIdsCache)
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ func getMockStore() *mocks.Store {
|
|||||||
mockChannelStore.On("GetGuestCount", "id", false).Return(mockGuestCount, nil)
|
mockChannelStore.On("GetGuestCount", "id", false).Return(mockGuestCount, nil)
|
||||||
mockStore.On("Channel").Return(&mockChannelStore)
|
mockStore.On("Channel").Return(&mockChannelStore)
|
||||||
|
|
||||||
|
mockPinnedPostsCount := int64(10)
|
||||||
|
mockChannelStore.On("GetPinnedPostCount", "id", true).Return(mockPinnedPostsCount, nil)
|
||||||
|
mockChannelStore.On("GetPinnedPostCount", "id", false).Return(mockPinnedPostsCount, nil)
|
||||||
|
|
||||||
fakePosts := &model.PostList{}
|
fakePosts := &model.PostList{}
|
||||||
fakeOptions := model.GetPostsOptions{ChannelId: "123", PerPage: 30}
|
fakeOptions := model.GetPostsOptions{ChannelId: "123", PerPage: 30}
|
||||||
mockPostStore := mocks.PostStore{}
|
mockPostStore := mocks.PostStore{}
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ const (
|
|||||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||||
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC = 1800 // 30 mins
|
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC = 1800 // 30 mins
|
||||||
|
|
||||||
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
|
||||||
CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC = 1800 // 30 mins
|
|
||||||
|
|
||||||
CHANNEL_CACHE_SEC = 900 // 15 mins
|
CHANNEL_CACHE_SEC = 900 // 15 mins
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -277,21 +274,18 @@ type publicChannel struct {
|
|||||||
Purpose string `json:"purpose"`
|
Purpose string `json:"purpose"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var channelPinnedPostCountsCache = utils.NewLru(CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SIZE)
|
|
||||||
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
||||||
var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE)
|
var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE)
|
||||||
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||||
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||||
|
|
||||||
func (s SqlChannelStore) ClearCaches() {
|
func (s SqlChannelStore) ClearCaches() {
|
||||||
channelPinnedPostCountsCache.Purge()
|
|
||||||
allChannelMembersForUserCache.Purge()
|
allChannelMembersForUserCache.Purge()
|
||||||
allChannelMembersNotifyPropsForChannelCache.Purge()
|
allChannelMembersNotifyPropsForChannelCache.Purge()
|
||||||
channelCache.Purge()
|
channelCache.Purge()
|
||||||
channelByNameCache.Purge()
|
channelByNameCache.Purge()
|
||||||
|
|
||||||
if s.metrics != nil {
|
if s.metrics != nil {
|
||||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel Pinned Post Counts - Purge")
|
|
||||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Purge")
|
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Purge")
|
||||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Purge")
|
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Purge")
|
||||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Purge")
|
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Purge")
|
||||||
@@ -1600,46 +1594,9 @@ func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
|
func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
|
||||||
channelPinnedPostCountsCache.Remove(channelId)
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel Pinned Post Counts - Remove by ChannelId")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s SqlChannelStore) GetPinnedPostCountFromCache(channelId string) int64 {
|
|
||||||
if cacheItem, ok := channelPinnedPostCountsCache.Get(channelId); ok {
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheHitCounter("Channel Pinned Post Counts")
|
|
||||||
}
|
|
||||||
return cacheItem.(int64)
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheMissCounter("Channel Pinned Post Counts")
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err := s.GetPinnedPostCount(channelId, true)
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) {
|
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) {
|
||||||
if allowFromCache {
|
|
||||||
if cacheItem, ok := channelPinnedPostCountsCache.Get(channelId); ok {
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheHitCounter("Channel Pinned Post Counts")
|
|
||||||
}
|
|
||||||
return cacheItem.(int64), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.metrics != nil {
|
|
||||||
s.metrics.IncrementMemCacheMissCounter("Channel Pinned Post Counts")
|
|
||||||
}
|
|
||||||
|
|
||||||
count, err := s.GetReplica().SelectInt(`
|
count, err := s.GetReplica().SelectInt(`
|
||||||
SELECT count(*)
|
SELECT count(*)
|
||||||
FROM Posts
|
FROM Posts
|
||||||
@@ -1652,10 +1609,6 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
|
|||||||
return 0, model.NewAppError("SqlChannelStore.GetPinnedPostCount", "store.sql_channel.get_pinnedpost_count.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
|
return 0, model.NewAppError("SqlChannelStore.GetPinnedPostCount", "store.sql_channel.get_pinnedpost_count.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if allowFromCache {
|
|
||||||
channelPinnedPostCountsCache.AddWithExpiresInSecs(channelId, count, CHANNEL_PINNEDPOSTS_COUNTS_CACHE_SEC)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ type ChannelStore interface {
|
|||||||
GetMemberCountFromCache(channelId string) int64
|
GetMemberCountFromCache(channelId string) int64
|
||||||
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
||||||
InvalidatePinnedPostCount(channelId string)
|
InvalidatePinnedPostCount(channelId string)
|
||||||
GetPinnedPostCountFromCache(channelId string) int64
|
|
||||||
GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
||||||
InvalidateGuestCount(channelId string)
|
InvalidateGuestCount(channelId string)
|
||||||
GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
||||||
|
|||||||
@@ -3200,12 +3200,6 @@ func testChannelStoreGetPinnedPostCount(t *testing.T, ss store.Store) {
|
|||||||
require.Nil(t, errGet, errGet)
|
require.Nil(t, errGet, errGet)
|
||||||
require.EqualValues(t, 2, count, "didn't return right count")
|
require.EqualValues(t, 2, count, "didn't return right count")
|
||||||
|
|
||||||
require.EqualValues(
|
|
||||||
t,
|
|
||||||
2,
|
|
||||||
ss.Channel().GetPinnedPostCountFromCache(o1.Id),
|
|
||||||
"should have saved 2 pinned post count")
|
|
||||||
|
|
||||||
ch2 := &model.Channel{
|
ch2 := &model.Channel{
|
||||||
TeamId: model.NewId(),
|
TeamId: model.NewId(),
|
||||||
DisplayName: "Name",
|
DisplayName: "Name",
|
||||||
@@ -3233,12 +3227,6 @@ func testChannelStoreGetPinnedPostCount(t *testing.T, ss store.Store) {
|
|||||||
count, errGet = ss.Channel().GetPinnedPostCount(o2.Id, true)
|
count, errGet = ss.Channel().GetPinnedPostCount(o2.Id, true)
|
||||||
require.Nil(t, errGet, errGet)
|
require.Nil(t, errGet, errGet)
|
||||||
require.EqualValues(t, 0, count, "should return 0")
|
require.EqualValues(t, 0, count, "should return 0")
|
||||||
|
|
||||||
require.EqualValues(
|
|
||||||
t,
|
|
||||||
0,
|
|
||||||
ss.Channel().GetPinnedPostCountFromCache(o2.Id),
|
|
||||||
"should have saved 0 pinned post count")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testChannelStoreMaxChannelsPerTeam(t *testing.T, ss store.Store) {
|
func testChannelStoreMaxChannelsPerTeam(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
@@ -646,13 +646,13 @@ func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit i
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeleted provides a mock function with given fields: team_id, offset, limit
|
// GetDeleted provides a mock function with given fields: team_id, offset, limit, userId
|
||||||
func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
|
func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
|
||||||
ret := _m.Called(team_id, offset, limit)
|
ret := _m.Called(team_id, offset, limit, userId)
|
||||||
|
|
||||||
var r0 *model.ChannelList
|
var r0 *model.ChannelList
|
||||||
if rf, ok := ret.Get(0).(func(string, int, int) *model.ChannelList); ok {
|
if rf, ok := ret.Get(0).(func(string, int, int, string) *model.ChannelList); ok {
|
||||||
r0 = rf(team_id, offset, limit)
|
r0 = rf(team_id, offset, limit, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.ChannelList)
|
r0 = ret.Get(0).(*model.ChannelList)
|
||||||
@@ -660,8 +660,8 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int, userId
|
|||||||
}
|
}
|
||||||
|
|
||||||
var r1 *model.AppError
|
var r1 *model.AppError
|
||||||
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
|
if rf, ok := ret.Get(1).(func(string, int, int, string) *model.AppError); ok {
|
||||||
r1 = rf(team_id, offset, limit)
|
r1 = rf(team_id, offset, limit, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(1) != nil {
|
if ret.Get(1) != nil {
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
@@ -1018,20 +1018,6 @@ func (_m *ChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPinnedPostCountFromCache provides a mock function with given fields: channelId
|
|
||||||
func (_m *ChannelStore) GetPinnedPostCountFromCache(channelId string) int64 {
|
|
||||||
ret := _m.Called(channelId)
|
|
||||||
|
|
||||||
var r0 int64
|
|
||||||
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
|
||||||
r0 = rf(channelId)
|
|
||||||
} else {
|
|
||||||
r0 = ret.Get(0).(int64)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPinnedPosts provides a mock function with given fields: channelId
|
// GetPinnedPosts provides a mock function with given fields: channelId
|
||||||
func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||||
ret := _m.Called(channelId)
|
ret := _m.Called(channelId)
|
||||||
@@ -1452,16 +1438,48 @@ func (_m *ChannelStore) SearchAllChannels(term string, opts store.ChannelSearchO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 *model.AppError
|
var r1 int64
|
||||||
if rf, ok := ret.Get(1).(func(string, store.ChannelSearchOpts) *model.AppError); ok {
|
if rf, ok := ret.Get(1).(func(string, store.ChannelSearchOpts) int64); ok {
|
||||||
r1 = rf(term, opts)
|
r1 = rf(term, opts)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Get(1).(int64)
|
||||||
|
}
|
||||||
|
|
||||||
|
var r2 *model.AppError
|
||||||
|
if rf, ok := ret.Get(2).(func(string, store.ChannelSearchOpts) *model.AppError); ok {
|
||||||
|
r2 = rf(term, opts)
|
||||||
|
} else {
|
||||||
|
if ret.Get(2) != nil {
|
||||||
|
r2 = ret.Get(2).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1, r2
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchArchivedInTeam provides a mock function with given fields: teamId, term, userId
|
||||||
|
func (_m *ChannelStore) SearchArchivedInTeam(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) {
|
||||||
|
ret := _m.Called(teamId, term, userId)
|
||||||
|
|
||||||
|
var r0 *model.ChannelList
|
||||||
|
if rf, ok := ret.Get(0).(func(string, string, string) *model.ChannelList); ok {
|
||||||
|
r0 = rf(teamId, term, userId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(*model.ChannelList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, term, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(1) != nil {
|
if ret.Get(1) != nil {
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0, 0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchForUserInTeam provides a mock function with given fields: userId, teamId, term, includeDeleted
|
// SearchForUserInTeam provides a mock function with given fields: userId, teamId, term, includeDeleted
|
||||||
@@ -1539,31 +1557,6 @@ func (_m *ChannelStore) SearchInTeam(teamId string, term string, includeDeleted
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchArchivedInTeam provides a mock function with given fields: teamId, term, userId
|
|
||||||
func (_m *ChannelStore) SearchArchivedInTeam(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) {
|
|
||||||
ret := _m.Called(teamId, term, userId)
|
|
||||||
|
|
||||||
var r0 *model.ChannelList
|
|
||||||
if rf, ok := ret.Get(0).(func(string, string, string) *model.ChannelList); ok {
|
|
||||||
r0 = rf(teamId, term, userId)
|
|
||||||
} else {
|
|
||||||
if ret.Get(0) != nil {
|
|
||||||
r0 = ret.Get(0).(*model.ChannelList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var r1 *model.AppError
|
|
||||||
if rf, ok := ret.Get(1).(func(string, string, string) *model.AppError); ok {
|
|
||||||
r1 = rf(teamId, term, userId)
|
|
||||||
} else {
|
|
||||||
if ret.Get(1) != nil {
|
|
||||||
r1 = ret.Get(1).(*model.AppError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return r0, r1
|
|
||||||
}
|
|
||||||
|
|
||||||
// SearchMore provides a mock function with given fields: userId, teamId, term
|
// SearchMore provides a mock function with given fields: userId, teamId, term
|
||||||
func (_m *ChannelStore) SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError) {
|
func (_m *ChannelStore) SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError) {
|
||||||
ret := _m.Called(userId, teamId, term)
|
ret := _m.Called(userId, teamId, term)
|
||||||
|
|||||||
@@ -1144,22 +1144,6 @@ func (s *TimerLayerChannelStore) GetPinnedPostCount(channelId string, allowFromC
|
|||||||
return resultVar0, resultVar1
|
return resultVar0, resultVar1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TimerLayerChannelStore) GetPinnedPostCountFromCache(channelId string) int64 {
|
|
||||||
start := timemodule.Now()
|
|
||||||
|
|
||||||
resultVar0 := s.ChannelStore.GetPinnedPostCountFromCache(channelId)
|
|
||||||
|
|
||||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
|
||||||
if s.Root.Metrics != nil {
|
|
||||||
success := "false"
|
|
||||||
if true {
|
|
||||||
success = "true"
|
|
||||||
}
|
|
||||||
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.GetPinnedPostCountFromCache", success, elapsed)
|
|
||||||
}
|
|
||||||
return resultVar0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||||
start := timemodule.Now()
|
start := timemodule.Now()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user