github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/store/local_cache_supplier_reactions.go (about) 1 // Copyright (c) 2016-present Xenia, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package store 5 6 import ( 7 "context" 8 9 "github.com/xzl8028/xenia-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) (*model.Reaction, *model.AppError) { 21 defer 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) (*model.Reaction, *model.AppError) { 26 defer 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) ([]*model.Reaction, *model.AppError) { 31 if result := s.doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil { 32 return result.Data.([]*model.Reaction), nil 33 } 34 35 reaction, err := s.Next().ReactionGetForPost(ctx, postId, hints...) 36 if err != nil { 37 return nil, err 38 } 39 40 result := NewSupplierResult() 41 result.Data = reaction 42 s.doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...) 43 44 return reaction, nil 45 } 46 47 func (s *LocalCacheSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *model.AppError { 48 // This could be improved. Right now we just clear the whole 49 // cache because we don't have a way find what post Ids have this emoji name. 50 defer s.doClearCacheCluster(s.reactionCache) 51 return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...) 52 } 53 54 func (s *LocalCacheSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) (int64, *model.AppError) { 55 // Don't bother to clear the cache as the posts will be gone anyway and the reactions being deleted will 56 // expire from the cache in due course. 57 return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit) 58 } 59 60 func (s *LocalCacheSupplier) ReactionsBulkGetForPosts(ctx context.Context, postIds []string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) { 61 // Ignoring this. 62 return s.Next().ReactionsBulkGetForPosts(ctx, postIds, hints...) 63 }