Migrate Channel.GetChannelsByIds to Sync by default (#11197)
* Migrate Channel.GetChannelsByIds to Sync by default * remove <-
Этот коммит содержится в:
коммит произвёл
Gabe Jackson
родитель
f97e6368c8
Коммит
7d08efc335
@@ -1759,11 +1759,11 @@ func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelLi
|
||||
|
||||
channelList := model.ChannelList{}
|
||||
if len(channelIds) > 0 {
|
||||
cresult := <-a.Srv.Store.Channel().GetChannelsByIds(channelIds)
|
||||
if cresult.Err != nil {
|
||||
return nil, cresult.Err
|
||||
channels, err := a.Srv.Store.Channel().GetChannelsByIds(channelIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, c := range cresult.Data.([]*model.Channel) {
|
||||
for _, c := range channels {
|
||||
if c.DeleteAt > 0 && !includeDeleted {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -2154,11 +2154,11 @@ func (a *App) getListOfAllowedChannelsForTeam(teamId string, viewRestrictions *m
|
||||
return channelIds, nil
|
||||
}
|
||||
|
||||
cresult := <-a.Srv.Store.Channel().GetChannelsByIds(viewRestrictions.Channels)
|
||||
if cresult.Err != nil {
|
||||
return nil, cresult.Err
|
||||
channels, err := a.Srv.Store.Channel().GetChannelsByIds(viewRestrictions.Channels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, c := range cresult.Data.([]*model.Channel) {
|
||||
for _, c := range channels {
|
||||
if c.TeamId == teamId {
|
||||
listOfAllowedChannels = append(listOfAllowedChannels, c.Id)
|
||||
}
|
||||
|
||||
@@ -1857,22 +1857,18 @@ func (s SqlChannelStore) GetAll(teamId string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetChannelsByIds(channelIds []string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
keys, params := MapStringsToQueryParams(channelIds, "Channel")
|
||||
func (s SqlChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) {
|
||||
keys, params := MapStringsToQueryParams(channelIds, "Channel")
|
||||
query := `SELECT * FROM Channels WHERE Id IN ` + keys + ` ORDER BY Name`
|
||||
|
||||
query := `SELECT * FROM Channels WHERE Id IN ` + keys + ` ORDER BY Name`
|
||||
var channels []*model.Channel
|
||||
_, err := s.GetReplica().Select(&channels, query, params)
|
||||
|
||||
var channels []*model.Channel
|
||||
_, err := s.GetReplica().Select(&channels, query, params)
|
||||
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprint(err))
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = channels
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprint(err))
|
||||
return nil, model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetForPost(postId string) store.StoreChannel {
|
||||
|
||||
@@ -155,7 +155,7 @@ type ChannelStore interface {
|
||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||
GetTeamChannels(teamId string) StoreChannel
|
||||
GetAll(teamId string) StoreChannel
|
||||
GetChannelsByIds(channelIds []string) StoreChannel
|
||||
GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError)
|
||||
GetForPost(postId string) StoreChannel
|
||||
SaveMember(member *model.ChannelMember) StoreChannel
|
||||
UpdateMember(member *model.ChannelMember) StoreChannel
|
||||
|
||||
@@ -484,30 +484,28 @@ func testChannelStoreGetChannelsByIds(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
|
||||
require.Nil(t, err)
|
||||
|
||||
if r1 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
cl := r1.Data.([]*model.Channel)
|
||||
if len(cl) != 2 {
|
||||
t.Fatal("invalid returned channels, expected 2 and got " + strconv.Itoa(len(cl)))
|
||||
if len(r1) != 2 {
|
||||
t.Fatal("invalid returned channels, expected 2 and got " + strconv.Itoa(len(r1)))
|
||||
}
|
||||
if cl[0].ToJson() != o1.ToJson() {
|
||||
if r1[0].ToJson() != o1.ToJson() {
|
||||
t.Fatal("invalid returned channel")
|
||||
}
|
||||
if cl[1].ToJson() != o2.ToJson() {
|
||||
if r1[1].ToJson() != o2.ToJson() {
|
||||
t.Fatal("invalid returned channel")
|
||||
}
|
||||
}
|
||||
|
||||
nonexistentId := "abcd1234"
|
||||
if r2 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, nonexistentId}); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
if r2, err := ss.Channel().GetChannelsByIds([]string{o1.Id, nonexistentId}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
cl := r2.Data.([]*model.Channel)
|
||||
if len(cl) != 1 {
|
||||
t.Fatal("invalid returned channels, expected 1 and got " + strconv.Itoa(len(cl)))
|
||||
if len(r2) != 1 {
|
||||
t.Fatal("invalid returned channels, expected 1 and got " + strconv.Itoa(len(r2)))
|
||||
}
|
||||
if cl[0].ToJson() != o1.ToJson() {
|
||||
if r2[0].ToJson() != o1.ToJson() {
|
||||
t.Fatal("invalid returned channel")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,19 +448,28 @@ func (_m *ChannelStore) GetChannelsBatchForIndexing(startTime int64, endTime int
|
||||
}
|
||||
|
||||
// GetChannelsByIds provides a mock function with given fields: channelIds
|
||||
func (_m *ChannelStore) GetChannelsByIds(channelIds []string) store.StoreChannel {
|
||||
func (_m *ChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) {
|
||||
ret := _m.Called(channelIds)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok {
|
||||
var r0 []*model.Channel
|
||||
if rf, ok := ret.Get(0).(func([]string) []*model.Channel); ok {
|
||||
r0 = rf(channelIds)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
|
||||
r1 = rf(channelIds)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetChannelsByScheme provides a mock function with given fields: schemeId, offset, limit
|
||||
|
||||
Ссылка в новой задаче
Block a user