Migrate Channel.GetChannelsByScheme to Sync by default (#11278)

This commit is contained in:
Shobhit Gupta
2019-07-02 13:06:03 -07:00
committed by Jesús Espino
parent d1a594e504
commit eea8df75b0
5 changed files with 29 additions and 30 deletions

View File

@@ -146,11 +146,7 @@ func (a *App) GetChannelsForScheme(scheme *model.Scheme, offset int, limit int)
if err := a.IsPhase2MigrationCompleted(); err != nil {
return nil, err
}
result := <-a.Srv.Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit)
if result.Err != nil {
return nil, result.Err
}
return result.Data.(model.ChannelList), nil
return a.Srv.Store.Channel().GetChannelsByScheme(scheme.Id, offset, limit)
}
func (a *App) IsPhase2MigrationCompleted() *model.AppError {

View File

@@ -2352,16 +2352,13 @@ func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) (*m
return dbMembers.ToModel(), nil
}
func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var channels model.ChannelList
_, err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = :SchemeId ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"SchemeId": schemeId, "Offset": offset, "Limit": limit})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.GetChannelsByScheme", "store.sql_channel.get_by_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError)
return
}
result.Data = channels
})
func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError) {
var channels model.ChannelList
_, err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = :SchemeId ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"SchemeId": schemeId, "Offset": offset, "Limit": limit})
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetChannelsByScheme", "store.sql_channel.get_by_scheme.app_error", nil, "schemeId="+schemeId+" "+err.Error(), http.StatusInternalServerError)
}
return channels, nil
}
// This function does the Advanced Permissions Phase 2 migration for ChannelMember objects. It performs the migration

View File

@@ -191,7 +191,7 @@ type ChannelStore interface {
AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError)
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
ClearCaches()
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError)
MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError)
ResetAllChannelSchemes() *model.AppError
ClearAllCustomRoleAssignments() *model.AppError

View File

@@ -3073,21 +3073,18 @@ func testChannelStoreGetChannelsByScheme(t *testing.T, ss store.Store) {
_, _ = ss.Channel().Save(c3, 100)
// Get the channels by a valid Scheme ID.
res1 := <-ss.Channel().GetChannelsByScheme(s1.Id, 0, 100)
assert.Nil(t, res1.Err)
d1 := res1.Data.(model.ChannelList)
d1, err := ss.Channel().GetChannelsByScheme(s1.Id, 0, 100)
assert.Nil(t, err)
assert.Len(t, d1, 2)
// Get the channels by a valid Scheme ID where there aren't any matching Channel.
res2 := <-ss.Channel().GetChannelsByScheme(s2.Id, 0, 100)
assert.Nil(t, res2.Err)
d2 := res2.Data.(model.ChannelList)
d2, err := ss.Channel().GetChannelsByScheme(s2.Id, 0, 100)
assert.Nil(t, err)
assert.Len(t, d2, 0)
// Get the channels by an invalid Scheme ID.
res3 := <-ss.Channel().GetChannelsByScheme(model.NewId(), 0, 100)
assert.Nil(t, res3.Err)
d3 := res3.Data.(model.ChannelList)
d3, err := ss.Channel().GetChannelsByScheme(model.NewId(), 0, 100)
assert.Nil(t, err)
assert.Len(t, d3, 0)
}

View File

@@ -620,19 +620,28 @@ func (_m *ChannelStore) GetChannelsByIds(channelIds []string) ([]*model.Channel,
}
// GetChannelsByScheme provides a mock function with given fields: schemeId, offset, limit
func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) store.StoreChannel {
func (_m *ChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, *model.AppError) {
ret := _m.Called(schemeId, offset, limit)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok {
var r0 model.ChannelList
if rf, ok := ret.Get(0).(func(string, int, int) model.ChannelList); ok {
r0 = rf(schemeId, offset, limit)
} else {
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, int, int) *model.AppError); ok {
r1 = rf(schemeId, offset, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetDeleted provides a mock function with given fields: team_id, offset, limit