2017-07-31 08:15:23 -07:00
|
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package store
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2017-09-06 23:05:10 -07:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
2017-07-31 08:15:23 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (s *LocalCacheSupplier) handleClusterInvalidateReaction(msg *model.ClusterMessage) {
|
|
|
|
|
if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
|
|
|
|
|
s.reactionCache.Purge()
|
|
|
|
|
} else {
|
|
|
|
|
s.reactionCache.Remove(msg.Data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
|
2018-08-30 10:28:58 -04:00
|
|
|
defer s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
|
2017-07-31 08:15:23 -07:00
|
|
|
return s.Next().ReactionSave(ctx, reaction, hints...)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
|
2018-08-30 13:25:25 -04:00
|
|
|
defer s.doInvalidateCacheCluster(s.reactionCache, reaction.PostId)
|
2017-07-31 08:15:23 -07:00
|
|
|
return s.Next().ReactionDelete(ctx, reaction, hints...)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) {
|
2017-09-14 12:01:44 -05:00
|
|
|
if result := s.doStandardReadCache(ctx, s.reactionCache, postId, hints...); result != nil {
|
2019-04-30 21:34:26 +02:00
|
|
|
return result.Data.([]*model.Reaction), nil
|
2017-07-31 08:15:23 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
reaction, err := s.Next().ReactionGetForPost(ctx, postId, hints...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2017-07-31 08:15:23 -07:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
result := NewSupplierResult()
|
|
|
|
|
result.Data = reaction
|
2017-09-14 12:01:44 -05:00
|
|
|
s.doStandardAddToCache(ctx, s.reactionCache, postId, result, hints...)
|
2017-07-31 08:15:23 -07:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
return reaction, nil
|
2017-07-31 08:15:23 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *model.AppError {
|
2017-07-31 08:15:23 -07:00
|
|
|
// This could be improved. Right now we just clear the whole
|
|
|
|
|
// cache because we don't have a way find what post Ids have this emoji name.
|
2018-08-30 13:25:25 -04:00
|
|
|
defer s.doClearCacheCluster(s.reactionCache)
|
2017-07-31 08:15:23 -07:00
|
|
|
return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...)
|
|
|
|
|
}
|
2017-09-15 17:35:55 +01:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) (int64, *model.AppError) {
|
2017-09-15 17:35:55 +01:00
|
|
|
// Don't bother to clear the cache as the posts will be gone anyway and the reactions being deleted will
|
|
|
|
|
// expire from the cache in due course.
|
|
|
|
|
return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit)
|
|
|
|
|
}
|
2019-01-03 14:35:08 +01:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *LocalCacheSupplier) ReactionsBulkGetForPosts(ctx context.Context, postIds []string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) {
|
2019-01-03 14:35:08 +01:00
|
|
|
// Ignoring this.
|
|
|
|
|
return s.Next().ReactionsBulkGetForPosts(ctx, postIds, hints...)
|
|
|
|
|
}
|