Migrate 'Channel.AutocompleteInTeamForSearch' to Sync by default (#11285)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
e53dba3848
Коммит
7e918e38bc
@@ -1774,11 +1774,7 @@ func (a *App) AutocompleteChannelsForSearch(teamId string, userId string, term s
|
|||||||
|
|
||||||
term = strings.TrimSpace(term)
|
term = strings.TrimSpace(term)
|
||||||
|
|
||||||
result := <-a.Srv.Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
return a.Srv.Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.ChannelList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||||
|
|||||||
@@ -1974,59 +1974,56 @@ func (s SqlChannelStore) AutocompleteInTeam(teamId string, term string, includeD
|
|||||||
return &channels, nil
|
return &channels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) store.StoreChannel {
|
func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
deleteFilter := "AND DeleteAt = 0"
|
||||||
deleteFilter := "AND DeleteAt = 0"
|
if includeDeleted {
|
||||||
if includeDeleted {
|
deleteFilter = ""
|
||||||
deleteFilter = ""
|
}
|
||||||
|
|
||||||
|
queryFormat := `
|
||||||
|
SELECT
|
||||||
|
C.*
|
||||||
|
FROM
|
||||||
|
Channels AS C
|
||||||
|
JOIN
|
||||||
|
ChannelMembers AS CM ON CM.ChannelId = C.Id
|
||||||
|
WHERE
|
||||||
|
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = 'G'))
|
||||||
|
AND CM.UserId = :UserId
|
||||||
|
` + deleteFilter + `
|
||||||
|
%v
|
||||||
|
LIMIT 50`
|
||||||
|
|
||||||
|
var channels model.ChannelList
|
||||||
|
|
||||||
|
if likeClause, likeTerm := s.buildLIKEClause(term, "Name, DisplayName, Purpose"); likeClause == "" {
|
||||||
|
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId}); err != nil {
|
||||||
|
return nil, model.NewAppError("SqlChannelStore.AutocompleteInTeamForSearch", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Using a UNION results in index_merge and fulltext queries and is much faster than the ref
|
||||||
|
// query you would get using an OR of the LIKE and full-text clauses.
|
||||||
|
fulltextClause, fulltextTerm := s.buildFulltextClause(term, "Name, DisplayName, Purpose")
|
||||||
|
likeQuery := fmt.Sprintf(queryFormat, "AND "+likeClause)
|
||||||
|
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
|
||||||
|
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
|
||||||
|
|
||||||
queryFormat := `
|
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm}); err != nil {
|
||||||
SELECT
|
return nil, model.NewAppError("SqlChannelStore.AutocompleteInTeamForSearch", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
|
||||||
C.*
|
|
||||||
FROM
|
|
||||||
Channels AS C
|
|
||||||
JOIN
|
|
||||||
ChannelMembers AS CM ON CM.ChannelId = C.Id
|
|
||||||
WHERE
|
|
||||||
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = 'G'))
|
|
||||||
AND CM.UserId = :UserId
|
|
||||||
` + deleteFilter + `
|
|
||||||
%v
|
|
||||||
LIMIT 50`
|
|
||||||
|
|
||||||
var channels model.ChannelList
|
|
||||||
|
|
||||||
if likeClause, likeTerm := s.buildLIKEClause(term, "Name, DisplayName, Purpose"); likeClause == "" {
|
|
||||||
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId}); err != nil {
|
|
||||||
result.Err = model.NewAppError("SqlChannelStore.AutocompleteInTeamForSearch", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Using a UNION results in index_merge and fulltext queries and is much faster than the ref
|
|
||||||
// query you would get using an OR of the LIKE and full-text clauses.
|
|
||||||
fulltextClause, fulltextTerm := s.buildFulltextClause(term, "Name, DisplayName, Purpose")
|
|
||||||
likeQuery := fmt.Sprintf(queryFormat, "AND "+likeClause)
|
|
||||||
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
|
|
||||||
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
|
|
||||||
|
|
||||||
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm}); err != nil {
|
|
||||||
result.Err = model.NewAppError("SqlChannelStore.AutocompleteInTeamForSearch", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
directChannels, err := s.autocompleteInTeamForSearchDirectMessages(userId, term)
|
directChannels, err := s.autocompleteInTeamForSearchDirectMessages(userId, term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = err
|
return nil, err
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
channels = append(channels, directChannels...)
|
channels = append(channels, directChannels...)
|
||||||
|
|
||||||
sort.Slice(channels, func(a, b int) bool {
|
sort.Slice(channels, func(a, b int) bool {
|
||||||
return strings.ToLower(channels[a].DisplayName) < strings.ToLower(channels[b].DisplayName)
|
return strings.ToLower(channels[a].DisplayName) < strings.ToLower(channels[b].DisplayName)
|
||||||
})
|
|
||||||
result.Data = &channels
|
|
||||||
})
|
})
|
||||||
|
return &channels, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) autocompleteInTeamForSearchDirectMessages(userId string, term string) ([]*model.Channel, *model.AppError) {
|
func (s SqlChannelStore) autocompleteInTeamForSearchDirectMessages(userId string, term string) ([]*model.Channel, *model.AppError) {
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ type ChannelStore interface {
|
|||||||
GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError)
|
GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError)
|
||||||
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) StoreChannel
|
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) StoreChannel
|
||||||
AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||||
AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) StoreChannel
|
AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||||
SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
|
SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
|
||||||
SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||||
SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError)
|
SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError)
|
||||||
|
|||||||
@@ -2672,9 +2672,8 @@ func testChannelStoreAutocompleteInTeamForSearch(t *testing.T, ss store.Store, s
|
|||||||
|
|
||||||
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.Channel().AutocompleteInTeamForSearch(o1.TeamId, m1.UserId, "ChannelA", false)
|
channels, err := ss.Channel().AutocompleteInTeamForSearch(o1.TeamId, m1.UserId, "ChannelA", false)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
channels := result.Data.(*model.ChannelList)
|
|
||||||
require.Len(t, *channels, 2)
|
require.Len(t, *channels, 2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,19 +85,28 @@ func (_m *ChannelStore) AutocompleteInTeam(teamId string, term string, includeDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AutocompleteInTeamForSearch provides a mock function with given fields: teamId, userId, term, includeDeleted
|
// AutocompleteInTeamForSearch provides a mock function with given fields: teamId, userId, term, includeDeleted
|
||||||
func (_m *ChannelStore) AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) store.StoreChannel {
|
func (_m *ChannelStore) AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
||||||
ret := _m.Called(teamId, userId, term, includeDeleted)
|
ret := _m.Called(teamId, userId, term, includeDeleted)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.ChannelList
|
||||||
if rf, ok := ret.Get(0).(func(string, string, string, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, string, bool) *model.ChannelList); ok {
|
||||||
r0 = rf(teamId, userId, term, includeDeleted)
|
r0 = rf(teamId, userId, term, includeDeleted)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.ChannelList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, string, bool) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, userId, term, includeDeleted)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearAllCustomRoleAssignments provides a mock function with given fields:
|
// ClearAllCustomRoleAssignments provides a mock function with given fields:
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user