Migrate Channel.GetChannelsByIds to Sync by default (#11197)

* Migrate Channel.GetChannelsByIds to Sync by default

* remove <-
Этот коммит содержится в:
Sheshagiri Rao Mallipedhi
2019-06-18 00:15:51 +05:30
коммит произвёл Gabe Jackson
родитель f97e6368c8
Коммит 7d08efc335
6 изменённых файлов: 44 добавлений и 41 удалений

Просмотреть файл

@@ -1759,11 +1759,11 @@ func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelLi
channelList := model.ChannelList{} channelList := model.ChannelList{}
if len(channelIds) > 0 { if len(channelIds) > 0 {
cresult := <-a.Srv.Store.Channel().GetChannelsByIds(channelIds) channels, err := a.Srv.Store.Channel().GetChannelsByIds(channelIds)
if cresult.Err != nil { if err != nil {
return nil, cresult.Err return nil, err
} }
for _, c := range cresult.Data.([]*model.Channel) { for _, c := range channels {
if c.DeleteAt > 0 && !includeDeleted { if c.DeleteAt > 0 && !includeDeleted {
continue continue
} }

Просмотреть файл

@@ -2154,11 +2154,11 @@ func (a *App) getListOfAllowedChannelsForTeam(teamId string, viewRestrictions *m
return channelIds, nil return channelIds, nil
} }
cresult := <-a.Srv.Store.Channel().GetChannelsByIds(viewRestrictions.Channels) channels, err := a.Srv.Store.Channel().GetChannelsByIds(viewRestrictions.Channels)
if cresult.Err != nil { if err != nil {
return nil, cresult.Err return nil, err
} }
for _, c := range cresult.Data.([]*model.Channel) { for _, c := range channels {
if c.TeamId == teamId { if c.TeamId == teamId {
listOfAllowedChannels = append(listOfAllowedChannels, c.Id) 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 { func (s SqlChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) {
return store.Do(func(result *store.StoreResult) { keys, params := MapStringsToQueryParams(channelIds, "Channel")
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 if err != nil {
_, err := s.GetReplica().Select(&channels, query, params) mlog.Error(fmt.Sprint(err))
return nil, model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError)
if err != nil { }
mlog.Error(fmt.Sprint(err)) return channels, nil
result.Err = model.NewAppError("SqlChannelStore.GetChannelsByIds", "store.sql_channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError)
} else {
result.Data = channels
}
})
} }
func (s SqlChannelStore) GetForPost(postId string) store.StoreChannel { func (s SqlChannelStore) GetForPost(postId string) store.StoreChannel {

Просмотреть файл

@@ -155,7 +155,7 @@ type ChannelStore interface {
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
GetTeamChannels(teamId string) StoreChannel GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel GetAll(teamId string) StoreChannel
GetChannelsByIds(channelIds []string) StoreChannel GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError)
GetForPost(postId string) StoreChannel GetForPost(postId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel SaveMember(member *model.ChannelMember) StoreChannel
UpdateMember(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) _, err = ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
require.Nil(t, err) require.Nil(t, err)
if r1 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); r1.Err != nil { if r1, err := ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
cl := r1.Data.([]*model.Channel) if len(r1) != 2 {
if len(cl) != 2 { t.Fatal("invalid returned channels, expected 2 and got " + strconv.Itoa(len(r1)))
t.Fatal("invalid returned channels, expected 2 and got " + strconv.Itoa(len(cl)))
} }
if cl[0].ToJson() != o1.ToJson() { if r1[0].ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel") t.Fatal("invalid returned channel")
} }
if cl[1].ToJson() != o2.ToJson() { if r1[1].ToJson() != o2.ToJson() {
t.Fatal("invalid returned channel") t.Fatal("invalid returned channel")
} }
} }
nonexistentId := "abcd1234" nonexistentId := "abcd1234"
if r2 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, nonexistentId}); r2.Err != nil { if r2, err := ss.Channel().GetChannelsByIds([]string{o1.Id, nonexistentId}); err != nil {
t.Fatal(r2.Err) t.Fatal(err)
} else { } else {
cl := r2.Data.([]*model.Channel) if len(r2) != 1 {
if len(cl) != 1 { t.Fatal("invalid returned channels, expected 1 and got " + strconv.Itoa(len(r2)))
t.Fatal("invalid returned channels, expected 1 and got " + strconv.Itoa(len(cl)))
} }
if cl[0].ToJson() != o1.ToJson() { if r2[0].ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel") 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 // 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) ret := _m.Called(channelIds)
var r0 store.StoreChannel var r0 []*model.Channel
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func([]string) []*model.Channel); ok {
r0 = rf(channelIds) r0 = rf(channelIds)
} else { } else {
if ret.Get(0) != nil { 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 // GetChannelsByScheme provides a mock function with given fields: schemeId, offset, limit