[MM-16568] Migrate "User.SearchInChannel" to Sync by default (#11417)
* implemented migration to sync * updated user.go to use explicit async approach
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
f8ba59ca9e
Коммит
1aa1363e63
18
app/user.go
18
app/user.go
@@ -1674,12 +1674,10 @@ func (a *App) SearchUsers(props *model.UserSearch, options *model.UserSearchOpti
|
|||||||
|
|
||||||
func (a *App) SearchUsersInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
func (a *App) SearchUsersInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||||
term = strings.TrimSpace(term)
|
term = strings.TrimSpace(term)
|
||||||
result := <-a.Srv.Store.User().SearchInChannel(channelId, term, options)
|
users, err := a.Srv.Store.User().SearchInChannel(channelId, term, options)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
users := result.Data.([]*model.User)
|
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
a.SanitizeProfile(user, options.IsAdmin)
|
a.SanitizeProfile(user, options.IsAdmin)
|
||||||
}
|
}
|
||||||
@@ -1847,13 +1845,21 @@ func (a *App) AutocompleteUsersInChannel(teamId string, channelId string, term s
|
|||||||
|
|
||||||
if !a.IsESAutocompletionEnabled() || err != nil {
|
if !a.IsESAutocompletionEnabled() || err != nil {
|
||||||
autocomplete = &model.UserAutocompleteInChannel{}
|
autocomplete = &model.UserAutocompleteInChannel{}
|
||||||
uchan := a.Srv.Store.User().SearchInChannel(channelId, term, options)
|
|
||||||
|
uchan := make(chan store.StoreResult, 1)
|
||||||
|
go func() {
|
||||||
|
users, err := a.Srv.Store.User().SearchInChannel(channelId, term, options)
|
||||||
|
uchan <- store.StoreResult{Data: users, Err: err}
|
||||||
|
close(uchan)
|
||||||
|
}()
|
||||||
|
|
||||||
nuchan := a.Srv.Store.User().SearchNotInChannel(teamId, channelId, term, options)
|
nuchan := a.Srv.Store.User().SearchNotInChannel(teamId, channelId, term, options)
|
||||||
|
|
||||||
result := <-uchan
|
result := <-uchan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
users := result.Data.([]*model.User)
|
users := result.Data.([]*model.User)
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
|
|||||||
@@ -1303,15 +1303,17 @@ func (us SqlUserStore) SearchNotInChannel(teamId string, channelId string, term
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) SearchInChannel(channelId string, term string, options *model.UserSearchOptions) store.StoreChannel {
|
func (us SqlUserStore) SearchInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := us.usersQuery.
|
||||||
query := us.usersQuery.
|
Join("ChannelMembers cm ON ( cm.UserId = u.Id AND cm.ChannelId = ? )", channelId).
|
||||||
Join("ChannelMembers cm ON ( cm.UserId = u.Id AND cm.ChannelId = ? )", channelId).
|
OrderBy("Username ASC").
|
||||||
OrderBy("Username ASC").
|
Limit(uint64(options.Limit))
|
||||||
Limit(uint64(options.Limit))
|
|
||||||
|
|
||||||
*result = us.performSearch(query, term, options)
|
result := us.performSearch(query, term, options)
|
||||||
})
|
if result.Err != nil {
|
||||||
|
return nil, result.Err
|
||||||
|
}
|
||||||
|
return result.Data.([]*model.User), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var escapeLikeSearchChar = []string{
|
var escapeLikeSearchChar = []string{
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ type UserStore interface {
|
|||||||
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
SearchInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel
|
||||||
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||||
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
AnalyticsGetInactiveUsersCount() (int64, *model.AppError)
|
||||||
|
|||||||
@@ -824,19 +824,28 @@ func (_m *UserStore) Search(teamId string, term string, options *model.UserSearc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SearchInChannel provides a mock function with given fields: channelId, term, options
|
// SearchInChannel provides a mock function with given fields: channelId, term, options
|
||||||
func (_m *UserStore) SearchInChannel(channelId string, term string, options *model.UserSearchOptions) store.StoreChannel {
|
func (_m *UserStore) SearchInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) {
|
||||||
ret := _m.Called(channelId, term, options)
|
ret := _m.Called(channelId, term, options)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.User
|
||||||
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, *model.UserSearchOptions) []*model.User); ok {
|
||||||
r0 = rf(channelId, term, options)
|
r0 = rf(channelId, term, options)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).([]*model.User)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, *model.UserSearchOptions) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId, term, options)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// SearchNotInChannel provides a mock function with given fields: teamId, channelId, term, options
|
// SearchNotInChannel provides a mock function with given fields: teamId, channelId, term, options
|
||||||
|
|||||||
@@ -2825,13 +2825,13 @@ func testUserStoreSearchInChannel(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.Description, func(t *testing.T) {
|
t.Run(testCase.Description, func(t *testing.T) {
|
||||||
result := <-ss.User().SearchInChannel(
|
users, err := ss.User().SearchInChannel(
|
||||||
testCase.ChannelId,
|
testCase.ChannelId,
|
||||||
testCase.Term,
|
testCase.Term,
|
||||||
testCase.Options,
|
testCase.Options,
|
||||||
)
|
)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
assertUsers(t, testCase.Expected, result.Data.([]*model.User))
|
assertUsers(t, testCase.Expected, users)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user