[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
288ed40e8f
Коммит
4fde004a5b
@@ -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) {
|
||||
|
||||
@@ -121,6 +121,12 @@ func (s SearchPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchPara
|
||||
return results, err
|
||||
}
|
||||
}
|
||||
|
||||
if *s.rootStore.config.SqlSettings.DisableDatabaseSearch {
|
||||
mlog.Debug("Returning empty results for post SearchPostsInTeam as the database search is disabled")
|
||||
return &model.PostSearchResults{PostList: model.NewPostList(), Matches: model.PostSearchMatches{}}, nil
|
||||
}
|
||||
|
||||
mlog.Debug("Using database search because no other search engine is available")
|
||||
return s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ func (s *SearchUserStore) Search(teamId, term string, options *model.UserSearchO
|
||||
return users, nil
|
||||
}
|
||||
}
|
||||
|
||||
mlog.Debug("Using database search because no other search engine is available")
|
||||
|
||||
return s.UserStore.Search(teamId, term, options)
|
||||
|
||||
Ссылка в новой задаче
Block a user