Migrate GetAllChannels and GetAllChannelsCount from ChannelStore to r… (#14765)

* Migrate GetAllChannels and GetAllChannelsCount from ChannelStore to return plain errors

* Moving i18n translations to the correct place

Co-authored-by: Jesús Espino <jespinog@gmail.com>
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-09 12:18:01 -04:00
коммит произвёл GitHub
родитель 779099d1a9
Коммит cac154e62b
10 изменённых файлов: 60 добавлений и 58 удалений

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

@@ -1563,7 +1563,12 @@ func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*
NotAssociatedToGroup: opts.NotAssociatedToGroup,
IncludeDeleted: opts.IncludeDeleted,
}
return a.Srv().Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts)
channels, err := a.Srv().Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts)
if err != nil {
return nil, model.NewAppError("GetAllChannels", "app.channel.get_all_channels.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return channels, nil
}
func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.AppError) {
@@ -1575,7 +1580,12 @@ func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.A
NotAssociatedToGroup: opts.NotAssociatedToGroup,
IncludeDeleted: opts.IncludeDeleted,
}
return a.Srv().Store.Channel().GetAllChannelsCount(storeOpts)
count, err := a.Srv().Store.Channel().GetAllChannelsCount(storeOpts)
if err != nil {
return 0, model.NewAppError("GetAllChannelsCount", "app.channel.get_all_channels_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
}
func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {

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

@@ -2998,6 +2998,14 @@
"id": "app.channel.get.find.app_error",
"translation": "We encountered an error finding the channel."
},
{
"id": "app.channel.get_all_channels.app_error",
"translation": "Unable to get all the channels."
},
{
"id": "app.channel.get_all_channels_count.app_error",
"translation": "Unable to count all the channels."
},
{
"id": "app.channel.move_channel.members_do_not_match.error",
"translation": "Unable to move a channel unless all its members are already members of the destination team."
@@ -6126,10 +6134,6 @@
"id": "store.sql_channel.get_all.app_error",
"translation": "Unable to get all the channels."
},
{
"id": "store.sql_channel.get_all_channels.get.app_error",
"translation": "Unable to get all the channels."
},
{
"id": "store.sql_channel.get_all_direct.app_error",
"translation": "Unable to get all the direct channels."

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

@@ -702,7 +702,7 @@ func (s *OpenTracingLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetAllChannels(page int, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetAllChannels(page int, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannels")
s.Root.Store.SetContext(newCtx)
@@ -720,7 +720,7 @@ func (s *OpenTracingLayerChannelStore) GetAllChannels(page int, perPage int, opt
return resultVar0, resultVar1
}
func (s *OpenTracingLayerChannelStore) GetAllChannelsCount(opts ChannelSearchOpts) (int64, *model.AppError) {
func (s *OpenTracingLayerChannelStore) GetAllChannelsCount(opts ChannelSearchOpts) (int64, error) {
origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannelsCount")
s.Root.Store.SetContext(newCtx)

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

@@ -931,37 +931,37 @@ func (s SqlChannelStore) GetChannels(teamId string, userId string, includeDelete
return channels, nil
}
func (s SqlChannelStore) GetAllChannels(offset, limit int, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
func (s SqlChannelStore) GetAllChannels(offset, limit int, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, error) {
query := s.getAllChannelsQuery(opts, false)
query = query.OrderBy("c.DisplayName, Teams.DisplayName").Limit(uint64(limit)).Offset(uint64(offset))
queryString, args, err := query.ToSql()
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetAllChannels", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
return nil, errors.Wrap(err, "failed to create query")
}
data := &model.ChannelListWithTeamData{}
_, err = s.GetReplica().Select(data, queryString, args...)
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetAllChannels", "store.sql_channel.get_all_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
return nil, errors.Wrap(err, "failed to get all channels")
}
return data, nil
}
func (s SqlChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int64, *model.AppError) {
func (s SqlChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int64, error) {
query := s.getAllChannelsQuery(opts, true)
queryString, args, err := query.ToSql()
if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetAllChannelsCount", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
return 0, errors.Wrap(err, "failed to create query")
}
count, err := s.GetReplica().SelectInt(queryString, args...)
if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetAllChannelsCount", "store.sql_channel.get_all_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
return 0, errors.Wrap(err, "failed to count all channels")
}
return count, nil

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

@@ -149,8 +149,8 @@ type ChannelStore interface {
GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError)
GetDeleted(team_id string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError)
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
GetAllChannelsCount(opts ChannelSearchOpts) (int64, *model.AppError)
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error)
GetAllChannelsCount(opts ChannelSearchOpts) (int64, error)
GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)

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

@@ -3249,45 +3249,45 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlSupplier)
_, nErr = ss.Channel().Save(&c5, -1)
require.Nil(t, nErr)
list, err := ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{})
require.Nil(t, err)
list, nErr := ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{})
require.Nil(t, nErr)
assert.Len(t, *list, 2)
assert.Equal(t, c1.Id, (*list)[0].Id)
assert.Equal(t, "Name", (*list)[0].TeamDisplayName)
assert.Equal(t, c3.Id, (*list)[1].Id)
assert.Equal(t, "Name2", (*list)[1].TeamDisplayName)
count1, err := ss.Channel().GetAllChannelsCount(store.ChannelSearchOpts{})
require.Nil(t, err)
count1, nErr := ss.Channel().GetAllChannelsCount(store.ChannelSearchOpts{})
require.Nil(t, nErr)
list, err = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, err)
list, nErr = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, nErr)
assert.Len(t, *list, 3)
assert.Equal(t, c1.Id, (*list)[0].Id)
assert.Equal(t, "Name", (*list)[0].TeamDisplayName)
assert.Equal(t, c2.Id, (*list)[1].Id)
assert.Equal(t, c3.Id, (*list)[2].Id)
count2, err := ss.Channel().GetAllChannelsCount(store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, err)
count2, nErr := ss.Channel().GetAllChannelsCount(store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, nErr)
require.True(t, func() bool {
return count2 > count1
}())
list, err = ss.Channel().GetAllChannels(0, 1, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, err)
list, nErr = ss.Channel().GetAllChannels(0, 1, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nil(t, nErr)
assert.Len(t, *list, 1)
assert.Equal(t, c1.Id, (*list)[0].Id)
assert.Equal(t, "Name", (*list)[0].TeamDisplayName)
// Not associated to group
list, err = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{NotAssociatedToGroup: group.Id})
require.Nil(t, err)
list, nErr = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{NotAssociatedToGroup: group.Id})
require.Nil(t, nErr)
assert.Len(t, *list, 1)
// Exclude channel names
list, err = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{ExcludeChannelNames: []string{c1.Name}})
require.Nil(t, err)
list, nErr = ss.Channel().GetAllChannels(0, 10, store.ChannelSearchOpts{ExcludeChannelNames: []string{c1.Name}})
require.Nil(t, nErr)
assert.Len(t, *list, 1)
// Manually truncate Channels table until testlib can handle cleanups

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

@@ -28,8 +28,8 @@ func cleanupStoreState(t *testing.T, ss store.Store) {
}
//remove existing channels
allChannels, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nilf(t, err, "error cleaning all test channels: %v", err)
allChannels, nErr := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true})
require.Nilf(t, nErr, "error cleaning all test channels: %v", nErr)
for _, channel := range *allChannels {
nErr := ss.Channel().PermanentDelete(channel.Id)
require.Nil(t, nErr, "failed cleaning up test channel %s", channel.Id)

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

@@ -31,9 +31,7 @@ func (_m *ChannelMemberHistoryStore) GetUsersInChannelDuring(startTime int64, en
if rf, ok := ret.Get(1).(func(int64, int64, string) error); ok {
r1 = rf(startTime, endTime, channelId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(error)
}
r1 = ret.Error(1)
}
return r0, r1
@@ -47,9 +45,7 @@ func (_m *ChannelMemberHistoryStore) LogJoinEvent(userId string, channelId strin
if rf, ok := ret.Get(0).(func(string, string, int64) error); ok {
r0 = rf(userId, channelId, joinTime)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(error)
}
r0 = ret.Error(0)
}
return r0
@@ -63,9 +59,7 @@ func (_m *ChannelMemberHistoryStore) LogLeaveEvent(userId string, channelId stri
if rf, ok := ret.Get(0).(func(string, string, int64) error); ok {
r0 = rf(userId, channelId, leaveTime)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(error)
}
r0 = ret.Error(0)
}
return r0
@@ -86,9 +80,7 @@ func (_m *ChannelMemberHistoryStore) PermanentDeleteBatch(endTime int64, limit i
if rf, ok := ret.Get(1).(func(int64, int64) error); ok {
r1 = rf(endTime, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(error)
}
r1 = ret.Error(1)
}
return r0, r1

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

@@ -291,7 +291,7 @@ func (_m *ChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId stri
}
// GetAllChannels provides a mock function with given fields: page, perPage, opts
func (_m *ChannelStore) GetAllChannels(page int, perPage int, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
func (_m *ChannelStore) GetAllChannels(page int, perPage int, opts store.ChannelSearchOpts) (*model.ChannelListWithTeamData, error) {
ret := _m.Called(page, perPage, opts)
var r0 *model.ChannelListWithTeamData
@@ -303,20 +303,18 @@ func (_m *ChannelStore) GetAllChannels(page int, perPage int, opts store.Channel
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(int, int, store.ChannelSearchOpts) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(int, int, store.ChannelSearchOpts) error); ok {
r1 = rf(page, perPage, opts)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// GetAllChannelsCount provides a mock function with given fields: opts
func (_m *ChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int64, *model.AppError) {
func (_m *ChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int64, error) {
ret := _m.Called(opts)
var r0 int64
@@ -326,13 +324,11 @@ func (_m *ChannelStore) GetAllChannelsCount(opts store.ChannelSearchOpts) (int64
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(store.ChannelSearchOpts) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(store.ChannelSearchOpts) error); ok {
r1 = rf(opts)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1

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

@@ -664,7 +664,7 @@ func (s *TimerLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(chann
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetAllChannels(page int, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
func (s *TimerLayerChannelStore) GetAllChannels(page int, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetAllChannels(page, perPage, opts)
@@ -680,7 +680,7 @@ func (s *TimerLayerChannelStore) GetAllChannels(page int, perPage int, opts Chan
return resultVar0, resultVar1
}
func (s *TimerLayerChannelStore) GetAllChannelsCount(opts ChannelSearchOpts) (int64, *model.AppError) {
func (s *TimerLayerChannelStore) GetAllChannelsCount(opts ChannelSearchOpts) (int64, error) {
start := timemodule.Now()
resultVar0, resultVar1 := s.ChannelStore.GetAllChannelsCount(opts)