Channel.GetMoreChannels to sync by default (#11207)

* Channel.GetMoreChannels to sync by default

* var renamed data -> channels
Этот коммит содержится в:
Rodrigo Villablanca Vásquez
2019-06-17 10:27:19 -04:00
коммит произвёл Jesús Espino
родитель 9d41c7a583
Коммит 5a3fed4534
5 изменённых файлов: 65 добавлений и 64 удалений

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

@@ -1265,11 +1265,7 @@ func (a *App) GetDeletedChannels(teamId string, offset int, limit int) (*model.C
} }
func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) { func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
result := <-a.Srv.Store.Channel().GetMoreChannels(teamId, userId, offset, limit) return a.Srv.Store.Channel().GetMoreChannels(teamId, userId, offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(*model.ChannelList), nil
} }
func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) { func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {

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

@@ -993,49 +993,46 @@ func (s SqlChannelStore) GetAllChannels(offset int, limit int, opts store.Channe
}) })
} }
func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) store.StoreChannel { func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
return store.Do(func(result *store.StoreResult) { channels := &model.ChannelList{}
data := &model.ChannelList{} _, err := s.GetReplica().Select(channels, `
_, err := s.GetReplica().Select(data, ` SELECT
Channels.*
FROM
Channels
JOIN
PublicChannels c ON (c.Id = Channels.Id)
WHERE
c.TeamId = :TeamId
AND c.DeleteAt = 0
AND c.Id NOT IN (
SELECT SELECT
Channels.* c.Id
FROM FROM
Channels PublicChannels c
JOIN JOIN
PublicChannels c ON (c.Id = Channels.Id) ChannelMembers cm ON (cm.ChannelId = c.Id)
WHERE WHERE
c.TeamId = :TeamId c.TeamId = :TeamId
AND cm.UserId = :UserId
AND c.DeleteAt = 0 AND c.DeleteAt = 0
AND c.Id NOT IN ( )
SELECT ORDER BY
c.Id c.DisplayName
FROM LIMIT :Limit
PublicChannels c OFFSET :Offset
JOIN
ChannelMembers cm ON (cm.ChannelId = c.Id)
WHERE
c.TeamId = :TeamId
AND cm.UserId = :UserId
AND c.DeleteAt = 0
)
ORDER BY
c.DisplayName
LIMIT :Limit
OFFSET :Offset
`, map[string]interface{}{ `, map[string]interface{}{
"TeamId": teamId, "TeamId": teamId,
"UserId": userId, "UserId": userId,
"Limit": limit, "Limit": limit,
"Offset": offset, "Offset": offset,
})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.GetMoreChannels", "store.sql_channel.get_more_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
return
}
result.Data = data
}) })
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMoreChannels", "store.sql_channel.get_more_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
}
return channels, nil
} }
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) store.StoreChannel { func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) store.StoreChannel {

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

@@ -149,7 +149,7 @@ type ChannelStore interface {
GetDeleted(team_id string, offset int, limit int) StoreChannel GetDeleted(team_id string, offset int, limit int) StoreChannel
GetChannels(teamId string, userId string, includeDeleted bool) StoreChannel GetChannels(teamId string, userId string, includeDeleted bool) StoreChannel
GetAllChannels(page, perPage int, opts ChannelSearchOpts) StoreChannel GetAllChannels(page, perPage int, opts ChannelSearchOpts) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError)
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel GetChannelCounts(teamId string, userId string) StoreChannel

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

@@ -610,7 +610,7 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
m2.NotifyProps = model.GetDefaultChannelNotifyProps() m2.NotifyProps = model.GetDefaultChannelNotifyProps()
store.Must(ss.Channel().SaveMember(&m2)) store.Must(ss.Channel().SaveMember(&m2))
if err := ss.Channel().Delete(o1.Id, model.GetMillis()); err != nil { if err = ss.Channel().Delete(o1.Id, model.GetMillis()); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -618,7 +618,7 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
t.Fatal("should have been deleted") t.Fatal("should have been deleted")
} }
if err := ss.Channel().Delete(o3.Id, model.GetMillis()); err != nil { if err = ss.Channel().Delete(o3.Id, model.GetMillis()); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -630,9 +630,8 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
t.Fatal("invalid number of channels") t.Fatal("invalid number of channels")
} }
cresult = <-ss.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100) list, err = ss.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
require.Nil(t, cresult.Err) require.Nil(t, err)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 1 { if len(*list) != 1 {
t.Fatal("invalid number of channels") t.Fatal("invalid number of channels")
@@ -1272,9 +1271,9 @@ func testChannelStoreGetMoreChannels(t *testing.T, ss store.Store) {
})) }))
t.Run("only o3 listed in more channels", func(t *testing.T) { t.Run("only o3 listed in more channels", func(t *testing.T) {
result := <-ss.Channel().GetMoreChannels(teamId, userId, 0, 100) list, channelErr := ss.Channel().GetMoreChannels(teamId, userId, 0, 100)
require.Nil(t, result.Err) require.Nil(t, channelErr)
require.Equal(t, &model.ChannelList{&o3}, result.Data.(*model.ChannelList)) require.Equal(t, &model.ChannelList{&o3}, list)
}) })
// o6 is another channel on the team to which the user does not belong, and would thus // o6 is another channel on the team to which the user does not belong, and would thus
@@ -1303,21 +1302,21 @@ func testChannelStoreGetMoreChannels(t *testing.T, ss store.Store) {
require.Nil(t, err, "channel should have been deleted") require.Nil(t, err, "channel should have been deleted")
t.Run("both o3 and o6 listed in more channels", func(t *testing.T) { t.Run("both o3 and o6 listed in more channels", func(t *testing.T) {
result := <-ss.Channel().GetMoreChannels(teamId, userId, 0, 100) list, err := ss.Channel().GetMoreChannels(teamId, userId, 0, 100)
require.Nil(t, result.Err) require.Nil(t, err)
require.Equal(t, &model.ChannelList{&o3, &o6}, result.Data.(*model.ChannelList)) require.Equal(t, &model.ChannelList{&o3, &o6}, list)
}) })
t.Run("only o3 listed in more channels with offset 0, limit 1", func(t *testing.T) { t.Run("only o3 listed in more channels with offset 0, limit 1", func(t *testing.T) {
result := <-ss.Channel().GetMoreChannels(teamId, userId, 0, 1) list, err := ss.Channel().GetMoreChannels(teamId, userId, 0, 1)
require.Nil(t, result.Err) require.Nil(t, err)
require.Equal(t, &model.ChannelList{&o3}, result.Data.(*model.ChannelList)) require.Equal(t, &model.ChannelList{&o3}, list)
}) })
t.Run("only o6 listed in more channels with offset 1, limit 1", func(t *testing.T) { t.Run("only o6 listed in more channels with offset 1, limit 1", func(t *testing.T) {
result := <-ss.Channel().GetMoreChannels(teamId, userId, 1, 1) list, err := ss.Channel().GetMoreChannels(teamId, userId, 1, 1)
require.Nil(t, result.Err) require.Nil(t, err)
require.Equal(t, &model.ChannelList{&o6}, result.Data.(*model.ChannelList)) require.Equal(t, &model.ChannelList{&o6}, list)
}) })
t.Run("verify analytics for open channels", func(t *testing.T) { t.Run("verify analytics for open channels", func(t *testing.T) {

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

@@ -661,19 +661,28 @@ func (_m *ChannelStore) GetMembersForUserWithPagination(teamId string, userId st
} }
// GetMoreChannels provides a mock function with given fields: teamId, userId, offset, limit // GetMoreChannels provides a mock function with given fields: teamId, userId, offset, limit
func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) store.StoreChannel { func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
ret := _m.Called(teamId, userId, offset, limit) ret := _m.Called(teamId, userId, offset, limit)
var r0 store.StoreChannel var r0 *model.ChannelList
if rf, ok := ret.Get(0).(func(string, string, int, int) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, string, int, int) *model.ChannelList); ok {
r0 = rf(teamId, userId, offset, limit) r0 = rf(teamId, userId, offset, limit)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.ChannelList)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string, int, int) *model.AppError); ok {
r1 = rf(teamId, userId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetPinnedPosts provides a mock function with given fields: channelId // GetPinnedPosts provides a mock function with given fields: channelId