[MM-23535] Add disable database search flag and return empty posts results if set (#14245)

* [MM-23535] Add disable database search flag and return empty posts results if set

* Add UpdateConfig function for the SearchStore and hook it into the app lifecycle

* Add the config listener in the server instance instead of using FakeApp

* Instantiate searchlayer as a pointer to avoid passing around copies of it
Этот коммит содержится в:
Miguel de la Cruz
2020-05-13 14:00:57 +02:00
коммит произвёл GitHub
родитель 288ed40e8f
Коммит 4fde004a5b
6 изменённых файлов: 47 добавлений и 22 удалений

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

@@ -17,38 +17,44 @@ type SearchStore struct {
team *SearchTeamStore
channel *SearchChannelStore
post *SearchPostStore
config *model.Config
}
func NewSearchLayer(baseStore store.Store, searchEngine *searchengine.Broker) SearchStore {
searchStore := SearchStore{
func NewSearchLayer(baseStore store.Store, searchEngine *searchengine.Broker, cfg *model.Config) *SearchStore {
searchStore := &SearchStore{
Store: baseStore,
searchEngine: searchEngine,
config: cfg,
}
searchStore.channel = &SearchChannelStore{ChannelStore: baseStore.Channel(), rootStore: &searchStore}
searchStore.post = &SearchPostStore{PostStore: baseStore.Post(), rootStore: &searchStore}
searchStore.team = &SearchTeamStore{TeamStore: baseStore.Team(), rootStore: &searchStore}
searchStore.user = &SearchUserStore{UserStore: baseStore.User(), rootStore: &searchStore}
searchStore.channel = &SearchChannelStore{ChannelStore: baseStore.Channel(), rootStore: searchStore}
searchStore.post = &SearchPostStore{PostStore: baseStore.Post(), rootStore: searchStore}
searchStore.team = &SearchTeamStore{TeamStore: baseStore.Team(), rootStore: searchStore}
searchStore.user = &SearchUserStore{UserStore: baseStore.User(), rootStore: searchStore}
return searchStore
}
func (s SearchStore) Channel() store.ChannelStore {
func (s *SearchStore) UpdateConfig(cfg *model.Config) {
s.config = cfg
}
func (s *SearchStore) Channel() store.ChannelStore {
return s.channel
}
func (s SearchStore) Post() store.PostStore {
func (s *SearchStore) Post() store.PostStore {
return s.post
}
func (s SearchStore) Team() store.TeamStore {
func (s *SearchStore) Team() store.TeamStore {
return s.team
}
func (s SearchStore) User() store.UserStore {
func (s *SearchStore) User() store.UserStore {
return s.user
}
func (s SearchStore) indexUserFromID(userId string) {
func (s *SearchStore) indexUserFromID(userId string) {
user, err := s.User().Get(userId)
if err != nil {
return
@@ -56,7 +62,7 @@ func (s SearchStore) indexUserFromID(userId string) {
s.indexUser(user)
}
func (s SearchStore) indexUser(user *model.User) {
func (s *SearchStore) indexUser(user *model.User) {
for _, engine := range s.searchEngine.GetActiveEngines() {
if engine.IsIndexingEnabled() {
runIndexFn(engine, func(engineCopy searchengine.SearchEngineInterface) {