diff options
author | Joram Wilander <jwawilander@gmail.com> | 2018-02-09 17:47:22 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-02-09 14:47:22 -0800 |
commit | 3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6 (patch) | |
tree | 7623b855717697cbc4b7b45ab47f5c35c76b8c9c /store/sqlstore | |
parent | 0daac7e4fc05ecb64dbc162daff618569bb249cd (diff) | |
download | chat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.tar.gz chat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.tar.bz2 chat-3e0c3eff9f2ddec241cdb3f7a91230fd7c51a5f6.zip |
ABC-228 Update GetPosts caching to work for non-60 limits (#8233)
* Update GetPosts caching to work for non-60 limits
* Only cache on limits of 30/60 and add test
* Add comments clarifying 30 and 60 limits
Diffstat (limited to 'store/sqlstore')
-rw-r--r-- | store/sqlstore/post_store.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index bc336e70d..25c3c4913 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -322,7 +322,10 @@ type etagPosts struct { func (s SqlPostStore) InvalidateLastPostTimeCache(channelId string) { lastPostTimeCache.Remove(channelId) - lastPostsCache.Remove(channelId) + + // Keys are "{channelid}{limit}" and caching only occurs on limits of 30 and 60 + lastPostsCache.Remove(channelId + "30") + lastPostsCache.Remove(channelId + "60") } func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel { @@ -439,8 +442,9 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro return } - if allowFromCache && offset == 0 && limit == 60 { - if cacheItem, ok := lastPostsCache.Get(channelId); ok { + // Caching only occurs on limits of 30 and 60, the common limits requested by MM clients + if allowFromCache && offset == 0 && (limit == 60 || limit == 30) { + if cacheItem, ok := lastPostsCache.Get(fmt.Sprintf("%s%v", channelId, limit)); ok { if s.metrics != nil { s.metrics.IncrementMemCacheHitCounter("Last Posts Cache") } @@ -482,8 +486,9 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro list.MakeNonNil() - if offset == 0 && limit == 60 { - lastPostsCache.AddWithExpiresInSecs(channelId, list, LAST_POSTS_CACHE_SEC) + // Caching only occurs on limits of 30 and 60, the common limits requested by MM clients + if offset == 0 && (limit == 60 || limit == 30) { + lastPostsCache.AddWithExpiresInSecs(fmt.Sprintf("%s%v", channelId, limit), list, LAST_POSTS_CACHE_SEC) } result.Data = list |