Migrate Channel.GetChannelsBatchForIndexing to Sync by default (#11134)

This commit is contained in:
Jesús Espino
2019-06-18 18:55:03 +02:00
committed by GitHub
parent d1569c48d2
commit 242c4f2c66
4 changed files with 46 additions and 40 deletions

View File

@@ -2608,33 +2608,30 @@ func (s SqlChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId s
})
}
func (s SqlChannelStore) GetChannelsBatchForIndexing(startTime, endTime int64, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var channels []*model.Channel
_, err1 := s.GetSearchReplica().Select(&channels,
`SELECT
*
FROM
Channels
WHERE
Type = 'O'
AND
CreateAt >= :StartTime
AND
CreateAt < :EndTime
ORDER BY
CreateAt
LIMIT
:NumChannels`,
map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumChannels": limit})
func (s SqlChannelStore) GetChannelsBatchForIndexing(startTime, endTime int64, limit int) ([]*model.Channel, *model.AppError) {
query :=
`SELECT
*
FROM
Channels
WHERE
Type = 'O'
AND
CreateAt >= :StartTime
AND
CreateAt < :EndTime
ORDER BY
CreateAt
LIMIT
:NumChannels`
if err1 != nil {
result.Err = model.NewAppError("SqlChannelStore.GetChannelsBatchForIndexing", "store.sql_channel.get_channels_batch_for_indexing.get.app_error", nil, err1.Error(), http.StatusInternalServerError)
return
}
var channels []*model.Channel
_, err := s.GetSearchReplica().Select(&channels, query, map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumChannels": limit})
if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetChannelsBatchForIndexing", "store.sql_channel.get_channels_batch_for_indexing.get.app_error", nil, err.Error(), http.StatusInternalServerError)
}
result.Data = channels
})
return channels, nil
}
func (s SqlChannelStore) UserBelongsToChannels(userId string, channelIds []string) store.StoreChannel {

View File

@@ -198,7 +198,7 @@ type ChannelStore interface {
GetAllDirectChannelsForExportAfter(limit int, afterId string) StoreChannel
GetChannelMembersForExport(userId string, teamId string) StoreChannel
RemoveAllDeactivatedMembers(channelId string) StoreChannel
GetChannelsBatchForIndexing(startTime, endTime int64, limit int) StoreChannel
GetChannelsBatchForIndexing(startTime, endTime int64, limit int) ([]*model.Channel, *model.AppError)
UserBelongsToChannels(userId string, channelIds []string) StoreChannel
}

View File

@@ -3650,18 +3650,18 @@ func testChannelStoreGetChannelsBatchForIndexing(t *testing.T, ss store.Store) {
endTime := c6.CreateAt
// First and last channel should be outside the range
res1 := <-ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 1000)
assert.Nil(t, res1.Err)
assert.ElementsMatch(t, []*model.Channel{c2, c3, c5}, res1.Data)
channels, err := ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 1000)
assert.Nil(t, err)
assert.ElementsMatch(t, []*model.Channel{c2, c3, c5}, channels)
// Update the endTime, last channel should be in
endTime = model.GetMillis()
res2 := <-ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 1000)
assert.Nil(t, res2.Err)
assert.ElementsMatch(t, []*model.Channel{c2, c3, c5, c6}, res2.Data)
channels, err = ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 1000)
assert.Nil(t, err)
assert.ElementsMatch(t, []*model.Channel{c2, c3, c5, c6}, channels)
// Testing the limit
res3 := <-ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 2)
assert.Nil(t, res3.Err)
assert.ElementsMatch(t, []*model.Channel{c2, c3}, res3.Data)
channels, err = ss.Channel().GetChannelsBatchForIndexing(startTime, endTime, 2)
assert.Nil(t, err)
assert.ElementsMatch(t, []*model.Channel{c2, c3}, channels)
}

View File

@@ -441,19 +441,28 @@ func (_m *ChannelStore) GetChannels(teamId string, userId string, includeDeleted
}
// GetChannelsBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
func (_m *ChannelStore) GetChannelsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel {
func (_m *ChannelStore) GetChannelsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.Channel, *model.AppError) {
ret := _m.Called(startTime, endTime, limit)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(int64, int64, int) store.StoreChannel); ok {
var r0 []*model.Channel
if rf, ok := ret.Get(0).(func(int64, int64, int) []*model.Channel); ok {
r0 = rf(startTime, endTime, limit)
} 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(int64, int64, int) *model.AppError); ok {
r1 = rf(startTime, endTime, limit)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetChannelsByIds provides a mock function with given fields: channelIds