* Adding Reaction store cache layer example

* Implementing reaction store in new caching system.

* Redis for reaction store

* Adding redis library

* Adding invalidation for DeleteAllWithEmojiName and other minor enhancements
Этот коммит содержится в:
Christopher Speller
2017-07-31 08:15:23 -07:00
коммит произвёл GitHub
родитель 6f4e38d129
Коммит 09b49c26dd
86 изменённых файлов: 16829 добавлений и 362 удалений

Просмотреть файл

@@ -6,38 +6,54 @@ package store
import (
"context"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
)
const (
ENABLE_EXPERIMENTAL_REDIS = false
)
type LayeredStore struct {
TmpContext context.Context
ReactionStore ReactionStore
DatabaseLayer *SqlSupplier
TmpContext context.Context
ReactionStore ReactionStore
DatabaseLayer *SqlSupplier
LocalCacheLayer *LocalCacheSupplier
RedisLayer *RedisSupplier
LayerChainHead LayeredStoreSupplier
}
func NewLayeredStore() Store {
return &LayeredStore{
TmpContext: context.TODO(),
ReactionStore: &LayeredReactionStore{},
DatabaseLayer: NewSqlSupplier(),
store := &LayeredStore{
TmpContext: context.TODO(),
DatabaseLayer: NewSqlSupplier(),
LocalCacheLayer: NewLocalCacheSupplier(),
}
store.ReactionStore = &LayeredReactionStore{store}
// Setup the chain
if ENABLE_EXPERIMENTAL_REDIS {
l4g.Debug("Experimental redis enabled.")
store.RedisLayer = NewRedisSupplier()
store.RedisLayer.SetChainNext(store.DatabaseLayer)
store.LayerChainHead = store.RedisLayer
} else {
store.LocalCacheLayer.SetChainNext(store.DatabaseLayer)
store.LayerChainHead = store.LocalCacheLayer
}
return store
}
type QueryFunction func(LayeredStoreSupplier) LayeredStoreSupplierResult
type QueryFunction func(LayeredStoreSupplier) *LayeredStoreSupplierResult
func (s *LayeredStore) RunQuery(queryFunction QueryFunction) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
finalResult := StoreResult{}
// Logic for determining what layers to run
if result := queryFunction(s.DatabaseLayer); result.Err == nil {
finalResult.Data = result.Result
} else {
finalResult.Err = result.Err
}
storeChannel <- finalResult
result := queryFunction(s.LayerChainHead)
storeChannel <- result.StoreResult
}()
return storeChannel
@@ -116,7 +132,7 @@ func (s *LayeredStore) FileInfo() FileInfoStore {
}
func (s *LayeredStore) Reaction() ReactionStore {
return s.DatabaseLayer.Reaction()
return s.ReactionStore
}
func (s *LayeredStore) Job() JobStore {
@@ -152,35 +168,25 @@ type LayeredReactionStore struct {
}
func (s *LayeredReactionStore) Save(reaction *model.Reaction) StoreChannel {
return s.RunQuery(func(supplier LayeredStoreSupplier) LayeredStoreSupplierResult {
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
return supplier.ReactionSave(s.TmpContext, reaction)
})
}
func (s *LayeredReactionStore) Delete(reaction *model.Reaction) StoreChannel {
return s.RunQuery(func(supplier LayeredStoreSupplier) LayeredStoreSupplierResult {
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
return supplier.ReactionDelete(s.TmpContext, reaction)
})
}
// TODO: DELETE ME
func (s *LayeredReactionStore) InvalidateCacheForPost(postId string) {
return
}
// TODO: DELETE ME
func (s *LayeredReactionStore) InvalidateCache() {
return
}
func (s *LayeredReactionStore) GetForPost(postId string, allowFromCache bool) StoreChannel {
return s.RunQuery(func(supplier LayeredStoreSupplier) LayeredStoreSupplierResult {
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
return supplier.ReactionGetForPost(s.TmpContext, postId)
})
}
func (s *LayeredReactionStore) DeleteAllWithEmojiName(emojiName string) StoreChannel {
return s.RunQuery(func(supplier LayeredStoreSupplier) LayeredStoreSupplierResult {
return s.RunQuery(func(supplier LayeredStoreSupplier) *LayeredStoreSupplierResult {
return supplier.ReactionDeleteAllWithEmojiName(s.TmpContext, emojiName)
})
}