2018-02-07 18:15:07 +00:00
|
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package store
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2018-04-27 12:49:45 -07:00
|
|
|
"github.com/mattermost/mattermost-server/mlog"
|
2018-02-07 18:15:07 +00:00
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
|
|
|
)
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
|
2018-02-07 18:15:07 +00:00
|
|
|
if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
return s.Next().ReactionSave(ctx, reaction, hints...)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
|
2018-02-07 18:15:07 +00:00
|
|
|
if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
return s.Next().ReactionDelete(ctx, reaction, hints...)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) {
|
|
|
|
|
var reaction []*model.Reaction
|
|
|
|
|
found, err := s.load("reactions:"+postId, &reaction)
|
2018-02-07 18:15:07 +00:00
|
|
|
if found {
|
2019-04-30 21:34:26 +02:00
|
|
|
return reaction, nil
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
2019-04-30 21:34:26 +02:00
|
|
|
|
2018-02-07 18:15:07 +00:00
|
|
|
if err != nil {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error("Redis encountered an error on read: " + err.Error())
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
reaction, appErr := s.Next().ReactionGetForPost(ctx, postId, hints...)
|
|
|
|
|
if appErr != nil {
|
|
|
|
|
return nil, appErr
|
|
|
|
|
}
|
2018-02-07 18:15:07 +00:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
if err := s.save("reactions:"+postId, reaction, REDIS_EXPIRY_TIME); err != nil {
|
2018-04-27 12:49:45 -07:00
|
|
|
mlog.Error("Redis encountered and error on write: " + err.Error())
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
return reaction, nil
|
2018-02-07 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *model.AppError {
|
2018-02-07 18:15:07 +00:00
|
|
|
// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
|
|
|
|
|
return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...)
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) (int64, *model.AppError) {
|
2018-02-07 18:15:07 +00:00
|
|
|
// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
|
|
|
|
|
return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit, hints...)
|
|
|
|
|
}
|
2019-01-03 14:35:08 +01:00
|
|
|
|
2019-04-30 21:34:26 +02:00
|
|
|
func (s *RedisSupplier) 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...)
|
|
|
|
|
}
|