Migrate channel to waitgroup for access the store in parallel (#16926)
* Migrate channel to waitgroup for access the store in parallel * Addressing PR review comments * Using a cleanest way of group errors * Reverting go.mod change
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
830594004b
Коммит
59d33b9002
@@ -14,6 +14,7 @@ import (
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/mattermost/gorp"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
@@ -1942,35 +1943,25 @@ func (us SqlUserStore) DemoteUserToGuest(userID string) (*model.User, error) {
|
||||
}
|
||||
|
||||
func (us SqlUserStore) AutocompleteUsersInChannel(teamId, channelId, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, error) {
|
||||
autocomplete := &model.UserAutocompleteInChannel{}
|
||||
uchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
users, err := us.SearchInChannel(channelId, term, options)
|
||||
uchan <- store.StoreResult{Data: users, NErr: err}
|
||||
close(uchan)
|
||||
}()
|
||||
|
||||
nuchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
users, err := us.SearchNotInChannel(teamId, channelId, term, options)
|
||||
nuchan <- store.StoreResult{Data: users, NErr: err}
|
||||
close(nuchan)
|
||||
}()
|
||||
|
||||
result := <-uchan
|
||||
if result.NErr != nil {
|
||||
return nil, result.NErr
|
||||
var usersInChannel, usersNotInChannel []*model.User
|
||||
g := errgroup.Group{}
|
||||
g.Go(func() (err error) {
|
||||
usersInChannel, err = us.SearchInChannel(channelId, term, options)
|
||||
return err
|
||||
})
|
||||
g.Go(func() (err error) {
|
||||
usersNotInChannel, err = us.SearchNotInChannel(teamId, channelId, term, options)
|
||||
return err
|
||||
})
|
||||
err := g.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
users := result.Data.([]*model.User)
|
||||
autocomplete.InChannel = users
|
||||
|
||||
result = <-nuchan
|
||||
if result.NErr != nil {
|
||||
return nil, result.NErr
|
||||
}
|
||||
users = result.Data.([]*model.User)
|
||||
autocomplete.OutOfChannel = users
|
||||
return autocomplete, nil
|
||||
return &model.UserAutocompleteInChannel{
|
||||
InChannel: usersInChannel,
|
||||
OutOfChannel: usersNotInChannel,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetKnownUsers returns the list of user ids of users with any direct
|
||||
|
||||
Ссылка в новой задаче
Block a user