[MM-15854] Migrate "Post.Search" to Sync by default (#11002)
* Migrate Post.Search to Sync by default * app/post.go channels modification * Removing tabs * Removing tabs * Reverting GetEtag modification * Fixing channel corruption error * Adding Done signal for goroutines * remove fixed length wg * undo wg short declaration * Removing one comment * Fixing change * Fixing store mocks * Fixing typo
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
0b90888e73
Коммит
89d8dd6816
20
app/post.go
20
app/post.go
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
@@ -895,7 +896,9 @@ func (a *App) parseAndFetchChannelIdByNameFromInFilter(channelName, userId, team
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) searchPostsInTeam(teamId string, userId string, paramsList []*model.SearchParams, modifierFun func(*model.SearchParams)) (*model.PostList, *model.AppError) {
|
func (a *App) searchPostsInTeam(teamId string, userId string, paramsList []*model.SearchParams, modifierFun func(*model.SearchParams)) (*model.PostList, *model.AppError) {
|
||||||
channels := []store.StoreChannel{}
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
pchan := make(chan store.StoreResult, len(paramsList))
|
||||||
|
|
||||||
for _, params := range paramsList {
|
for _, params := range paramsList {
|
||||||
// Don't allow users to search for everything.
|
// Don't allow users to search for everything.
|
||||||
@@ -903,12 +906,21 @@ func (a *App) searchPostsInTeam(teamId string, userId string, paramsList []*mode
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
modifierFun(params)
|
modifierFun(params)
|
||||||
channels = append(channels, a.Srv.Store.Post().Search(teamId, userId, params))
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func(params *model.SearchParams) {
|
||||||
|
defer wg.Done()
|
||||||
|
postList, err := a.Srv.Store.Post().Search(teamId, userId, params)
|
||||||
|
pchan <- store.StoreResult{Data: postList, Err: err}
|
||||||
|
}(params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
close(pchan)
|
||||||
|
|
||||||
posts := model.NewPostList()
|
posts := model.NewPostList()
|
||||||
for _, channel := range channels {
|
|
||||||
result := <-channel
|
for result := range pchan {
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -794,8 +794,7 @@ var specialSearchChar = []string{
|
|||||||
":",
|
":",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) store.StoreChannel {
|
func (s *SqlPostStore) Search(teamId string, userId string, params *model.SearchParams) (*model.PostList, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
queryParams := map[string]interface{}{
|
queryParams := map[string]interface{}{
|
||||||
"TeamId": teamId,
|
"TeamId": teamId,
|
||||||
"UserId": userId,
|
"UserId": userId,
|
||||||
@@ -803,10 +802,10 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
|
|||||||
|
|
||||||
termMap := map[string]bool{}
|
termMap := map[string]bool{}
|
||||||
terms := params.Terms
|
terms := params.Terms
|
||||||
|
list := model.NewPostList()
|
||||||
|
|
||||||
if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 && len(params.OnDate) == 0 && len(params.AfterDate) == 0 && len(params.BeforeDate) == 0 {
|
if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 && len(params.OnDate) == 0 && len(params.AfterDate) == 0 && len(params.BeforeDate) == 0 {
|
||||||
result.Data = []*model.Post{}
|
return list, nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchType := "Message"
|
searchType := "Message"
|
||||||
@@ -984,13 +983,13 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
|
|||||||
|
|
||||||
queryParams["Terms"] = terms
|
queryParams["Terms"] = terms
|
||||||
|
|
||||||
list := model.NewPostList()
|
|
||||||
|
|
||||||
_, err := s.GetSearchReplica().Select(&posts, searchQuery, queryParams)
|
_, err := s.GetSearchReplica().Select(&posts, searchQuery, queryParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn(fmt.Sprintf("Query error searching posts: %v", err.Error()))
|
mlog.Warn(fmt.Sprintf("Query error searching posts: %v", err.Error()))
|
||||||
// Don't return the error to the caller as it is of no use to the user. Instead return an empty set of search results.
|
// Don't return the error to the caller as it is of no use to the user. Instead return an empty set of search results.
|
||||||
} else {
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range posts {
|
for _, p := range posts {
|
||||||
if searchType == "Hashtags" {
|
if searchType == "Hashtags" {
|
||||||
exactMatch := false
|
exactMatch := false
|
||||||
@@ -1006,12 +1005,10 @@ func (s *SqlPostStore) Search(teamId string, userId string, params *model.Search
|
|||||||
list.AddPost(p)
|
list.AddPost(p)
|
||||||
list.AddOrder(p.Id)
|
list.AddOrder(p.Id)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
list.MakeNonNil()
|
list.MakeNonNil()
|
||||||
|
|
||||||
result.Data = list
|
return list, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) {
|
func (s *SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ type PostStore interface {
|
|||||||
GetPostIdAfterTime(channelId string, time int64) (string, *model.AppError)
|
GetPostIdAfterTime(channelId string, time int64) (string, *model.AppError)
|
||||||
GetPostIdBeforeTime(channelId string, time int64) (string, *model.AppError)
|
GetPostIdBeforeTime(channelId string, time int64) (string, *model.AppError)
|
||||||
GetEtag(channelId string, allowFromCache bool) string
|
GetEtag(channelId string, allowFromCache bool) string
|
||||||
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
Search(teamId string, userId string, params *model.SearchParams) (*model.PostList, *model.AppError)
|
||||||
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
||||||
AnalyticsPostCountsByDay(options *model.AnalyticsPostCountsOptions) (model.AnalyticsRows, *model.AppError)
|
AnalyticsPostCountsByDay(options *model.AnalyticsPostCountsOptions) (model.AnalyticsRows, *model.AppError)
|
||||||
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError)
|
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ package mocks
|
|||||||
|
|
||||||
import mock "github.com/stretchr/testify/mock"
|
import mock "github.com/stretchr/testify/mock"
|
||||||
import model "github.com/mattermost/mattermost-server/model"
|
import model "github.com/mattermost/mattermost-server/model"
|
||||||
import store "github.com/mattermost/mattermost-server/store"
|
|
||||||
|
|
||||||
// PostStore is an autogenerated mock type for the PostStore type
|
// PostStore is an autogenerated mock type for the PostStore type
|
||||||
type PostStore struct {
|
type PostStore struct {
|
||||||
@@ -717,19 +716,28 @@ func (_m *PostStore) Save(post *model.Post) (*model.Post, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search provides a mock function with given fields: teamId, userId, params
|
// Search provides a mock function with given fields: teamId, userId, params
|
||||||
func (_m *PostStore) Search(teamId string, userId string, params *model.SearchParams) store.StoreChannel {
|
func (_m *PostStore) Search(teamId string, userId string, params *model.SearchParams) (*model.PostList, *model.AppError) {
|
||||||
ret := _m.Called(teamId, userId, params)
|
ret := _m.Called(teamId, userId, params)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.PostList
|
||||||
if rf, ok := ret.Get(0).(func(string, string, *model.SearchParams) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, *model.SearchParams) *model.PostList); ok {
|
||||||
r0 = rf(teamId, userId, params)
|
r0 = rf(teamId, userId, params)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.PostList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, *model.SearchParams) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, userId, params)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update provides a mock function with given fields: newPost, oldPost
|
// Update provides a mock function with given fields: newPost, oldPost
|
||||||
|
|||||||
@@ -1343,7 +1343,8 @@ func testPostStoreSearch(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
for _, tc := range tt {
|
for _, tc := range tt {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
result := (<-ss.Post().Search(teamId, userId, tc.searchParams)).Data.(*model.PostList)
|
result, err := ss.Post().Search(teamId, userId, tc.searchParams)
|
||||||
|
require.Nil(t, err)
|
||||||
require.Len(t, result.Order, tc.expectedResultsCount)
|
require.Len(t, result.Order, tc.expectedResultsCount)
|
||||||
for _, expectedMessageResultId := range tc.expectedMessageResultIds {
|
for _, expectedMessageResultId := range tc.expectedMessageResultIds {
|
||||||
assert.Contains(t, result.Order, expectedMessageResultId)
|
assert.Contains(t, result.Order, expectedMessageResultId)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user