github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/store/local_cache_supplier_reactions.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package store 5 6 import ( 7 "context" 8 9 "github.com/mattermost/mattermost-server/model" 10 ) 11 12 func (s *LocalCacheSupplier) handleClusterInvalidateReaction(msg *model.ClusterMessage) { 13 if msg.Data == CLEAR_CACHE_MESSAGE_DATA { 14 s.reactionCache.Purge() 15 } else { 16 s.reactionCache.Remove(msg.Data) 17 } 18 } 19 20 func (s *LocalCacheSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 21 s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId) 22 return s.Next().ReactionSave(ctx, reaction, hints...) 23 } 24 25 func (s *LocalCacheSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 26 s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId) 27 return s.Next().ReactionDelete(ctx, reaction, hints...) 28 } 29 30 func (s *LocalCacheSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 31 if result := s.doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil { 32 return result 33 } 34 35 result := s.Next().ReactionGetForPost(ctx, postId, hints...) 36 37 s.doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...) 38 39 return result 40 } 41 42 func (s *LocalCacheSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 43 // This could be improved. Right now we just clear the whole 44 // cache because we don't have a way find what post Ids have this emoji name. 45 s.doClearCacheCluster(s.reactionCache) 46 return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...) 47 } 48 49 func (s *LocalCacheSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 50 // Don't bother to clear the cache as the posts will be gone anyway and the reactions being deleted will 51 // expire from the cache in due course. 52 return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit) 53 }