github.com/demisto/mattermost-server@v4.9.0-rc3+incompatible/store/redis_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  	l4g "github.com/alecthomas/log4go"
    10  
    11  	"github.com/mattermost/mattermost-server/model"
    12  )
    13  
    14  func (s *RedisSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
    15  	if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
    16  		l4g.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
    17  	}
    18  	return s.Next().ReactionSave(ctx, reaction, hints...)
    19  }
    20  
    21  func (s *RedisSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
    22  	if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
    23  		l4g.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
    24  	}
    25  	return s.Next().ReactionDelete(ctx, reaction, hints...)
    26  }
    27  
    28  func (s *RedisSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
    29  	var resultdata []*model.Reaction
    30  	found, err := s.load("reactions:"+postId, &resultdata)
    31  	if found {
    32  		result := NewSupplierResult()
    33  		result.Data = resultdata
    34  		return result
    35  	}
    36  	if err != nil {
    37  		l4g.Error("Redis encountered an error on read: " + err.Error())
    38  	}
    39  
    40  	result := s.Next().ReactionGetForPost(ctx, postId, hints...)
    41  
    42  	if err := s.save("reactions:"+postId, result.Data, REDIS_EXPIRY_TIME); err != nil {
    43  		l4g.Error("Redis encountered and error on write: " + err.Error())
    44  	}
    45  
    46  	return result
    47  }
    48  
    49  func (s *RedisSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
    50  	// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
    51  	return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...)
    52  }
    53  
    54  func (s *RedisSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
    55  	// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
    56  	return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit, hints...)
    57  }