MM-30304 - Handle collapsed threads in page apis (#17064)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f2e27a39da
Коммит
4aa6c863c3
@@ -5112,7 +5112,7 @@ func (s *OpenTracingLayerPostStore) GetParentsForExportAfter(limit int, afterID
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
|
||||
func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostAfterTime")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -5121,7 +5121,7 @@ func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int6
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -5130,7 +5130,7 @@ func (s *OpenTracingLayerPostStore) GetPostAfterTime(channelID string, time int6
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
|
||||
func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostIdAfterTime")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -5139,7 +5139,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time in
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
@@ -5148,7 +5148,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdAfterTime(channelID string, time in
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
|
||||
func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetPostIdBeforeTime")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -5157,7 +5157,7 @@ func (s *OpenTracingLayerPostStore) GetPostIdBeforeTime(channelID string, time i
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -5514,11 +5514,11 @@ func (s *RetryLayerPostStore) GetParentsForExportAfter(limit int, afterID string
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
|
||||
func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -5534,11 +5534,11 @@ func (s *RetryLayerPostStore) GetPostAfterTime(channelID string, time int64) (*m
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
|
||||
func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
@@ -5554,11 +5554,11 @@ func (s *RetryLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
|
||||
func (s *RetryLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -1026,15 +1026,15 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostIdBeforeTime(channelId string, time int64) (string, error) {
|
||||
return s.getPostIdAroundTime(channelId, time, true)
|
||||
func (s *SqlPostStore) GetPostIdBeforeTime(channelId string, time int64, collapsedThreads bool) (string, error) {
|
||||
return s.getPostIdAroundTime(channelId, time, true, collapsedThreads)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostIdAfterTime(channelId string, time int64) (string, error) {
|
||||
return s.getPostIdAroundTime(channelId, time, false)
|
||||
func (s *SqlPostStore) GetPostIdAfterTime(channelId string, time int64, collapsedThreads bool) (string, error) {
|
||||
return s.getPostIdAroundTime(channelId, time, false, collapsedThreads)
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before bool) (string, error) {
|
||||
func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before bool, collapsedThreads bool) (string, error) {
|
||||
var direction sq.Sqlizer
|
||||
var sort string
|
||||
if before {
|
||||
@@ -1053,14 +1053,18 @@ func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before
|
||||
table += " USE INDEX(idx_posts_channel_id_delete_at_create_at)"
|
||||
}
|
||||
|
||||
conditions := sq.And{
|
||||
direction,
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}
|
||||
if collapsedThreads {
|
||||
conditions = sq.And{conditions, sq.Eq{"RootId": ""}}
|
||||
}
|
||||
query := s.getQueryBuilder().
|
||||
Select("Id").
|
||||
From(table).
|
||||
Where(sq.And{
|
||||
direction,
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}).
|
||||
Where(conditions).
|
||||
// Adding ChannelId and DeleteAt order columns
|
||||
// to let mysql choose the "idx_posts_channel_id_delete_at_create_at" index always.
|
||||
// See MM-23369.
|
||||
@@ -1082,7 +1086,7 @@ func (s *SqlPostStore) getPostIdAroundTime(channelId string, time int64, before
|
||||
return postId, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64) (*model.Post, error) {
|
||||
func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64, collapsedThreads bool) (*model.Post, error) {
|
||||
table := "Posts"
|
||||
// We force MySQL to use the right index to prevent it from accidentally
|
||||
// using the index_merge_intersection optimization.
|
||||
@@ -1090,15 +1094,18 @@ func (s *SqlPostStore) GetPostAfterTime(channelId string, time int64) (*model.Po
|
||||
if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
table += " USE INDEX(idx_posts_channel_id_delete_at_create_at)"
|
||||
}
|
||||
|
||||
conditions := sq.And{
|
||||
sq.Gt{"CreateAt": time},
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}
|
||||
if collapsedThreads {
|
||||
conditions = sq.And{conditions, sq.Eq{"RootId": ""}}
|
||||
}
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From(table).
|
||||
Where(sq.And{
|
||||
sq.Gt{"CreateAt": time},
|
||||
sq.Eq{"ChannelId": channelId},
|
||||
sq.Eq{"DeleteAt": int(0)},
|
||||
}).
|
||||
Where(conditions).
|
||||
// Adding ChannelId and DeleteAt order columns
|
||||
// to let mysql choose the "idx_posts_channel_id_delete_at_create_at" index always.
|
||||
// See MM-23369.
|
||||
|
||||
@@ -287,9 +287,9 @@ type PostStore interface {
|
||||
GetPostsBefore(options model.GetPostsOptions) (*model.PostList, error)
|
||||
GetPostsAfter(options model.GetPostsOptions) (*model.PostList, error)
|
||||
GetPostsSince(options model.GetPostsSinceOptions, allowFromCache bool) (*model.PostList, error)
|
||||
GetPostAfterTime(channelID string, time int64) (*model.Post, error)
|
||||
GetPostIdAfterTime(channelID string, time int64) (string, error)
|
||||
GetPostIdBeforeTime(channelID string, time int64) (string, error)
|
||||
GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error)
|
||||
GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error)
|
||||
GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error)
|
||||
GetEtag(channelID string, allowFromCache bool, collapsedThreads bool) string
|
||||
Search(teamID string, userId string, params *model.SearchParams) (*model.PostList, error)
|
||||
AnalyticsUserCountsWithPostsByDay(teamID string) (model.AnalyticsRows, error)
|
||||
|
||||
@@ -310,13 +310,13 @@ func (_m *PostStore) GetParentsForExportAfter(limit int, afterID string) ([]*mod
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPostAfterTime provides a mock function with given fields: channelID, time
|
||||
func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
|
||||
ret := _m.Called(channelID, time)
|
||||
// GetPostAfterTime provides a mock function with given fields: channelID, time, collapsedThreads
|
||||
func (_m *PostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
|
||||
ret := _m.Called(channelID, time, collapsedThreads)
|
||||
|
||||
var r0 *model.Post
|
||||
if rf, ok := ret.Get(0).(func(string, int64) *model.Post); ok {
|
||||
r0 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(0).(func(string, int64, bool) *model.Post); ok {
|
||||
r0 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Post)
|
||||
@@ -324,8 +324,8 @@ func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
|
||||
r1 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
|
||||
r1 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -333,20 +333,20 @@ func (_m *PostStore) GetPostAfterTime(channelID string, time int64) (*model.Post
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPostIdAfterTime provides a mock function with given fields: channelID, time
|
||||
func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
|
||||
ret := _m.Called(channelID, time)
|
||||
// GetPostIdAfterTime provides a mock function with given fields: channelID, time, collapsedThreads
|
||||
func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
ret := _m.Called(channelID, time, collapsedThreads)
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(string, int64) string); ok {
|
||||
r0 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(0).(func(string, int64, bool) string); ok {
|
||||
r0 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
|
||||
r1 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
|
||||
r1 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
@@ -354,20 +354,20 @@ func (_m *PostStore) GetPostIdAfterTime(channelID string, time int64) (string, e
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPostIdBeforeTime provides a mock function with given fields: channelID, time
|
||||
func (_m *PostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
|
||||
ret := _m.Called(channelID, time)
|
||||
// GetPostIdBeforeTime provides a mock function with given fields: channelID, time, collapsedThreads
|
||||
func (_m *PostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
ret := _m.Called(channelID, time, collapsedThreads)
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func(string, int64) string); ok {
|
||||
r0 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(0).(func(string, int64, bool) string); ok {
|
||||
r0 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, int64) error); ok {
|
||||
r1 = rf(channelID, time)
|
||||
if rf, ok := ret.Get(1).(func(string, int64, bool) error); ok {
|
||||
r1 = rf(channelID, time, collapsedThreads)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -1579,39 +1579,39 @@ func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Post().Save(o2a)
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId1, err := ss.Post().GetPostIdBeforeTime(channelId, o0a.CreateAt)
|
||||
rPostId1, err := ss.Post().GetPostIdBeforeTime(channelId, o0a.CreateAt, false)
|
||||
require.Equal(t, rPostId1, o1.Id, "should return before post o1")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId1, err = ss.Post().GetPostIdAfterTime(channelId, o0b.CreateAt)
|
||||
rPostId1, err = ss.Post().GetPostIdAfterTime(channelId, o0b.CreateAt, false)
|
||||
require.Equal(t, rPostId1, o2.Id, "should return before post o2")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPost1, err := ss.Post().GetPostAfterTime(channelId, o0b.CreateAt)
|
||||
rPost1, err := ss.Post().GetPostAfterTime(channelId, o0b.CreateAt, false)
|
||||
require.Equal(t, rPost1.Id, o2.Id, "should return before post o2")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId2, err := ss.Post().GetPostIdBeforeTime(channelId, o0.CreateAt)
|
||||
rPostId2, err := ss.Post().GetPostIdBeforeTime(channelId, o0.CreateAt, false)
|
||||
require.Empty(t, rPostId2, "should return no post")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId2, err = ss.Post().GetPostIdAfterTime(channelId, o0.CreateAt)
|
||||
rPostId2, err = ss.Post().GetPostIdAfterTime(channelId, o0.CreateAt, false)
|
||||
require.Equal(t, rPostId2, o1.Id, "should return before post o1")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPost2, err := ss.Post().GetPostAfterTime(channelId, o0.CreateAt)
|
||||
rPost2, err := ss.Post().GetPostAfterTime(channelId, o0.CreateAt, false)
|
||||
require.Equal(t, rPost2.Id, o1.Id, "should return before post o1")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId3, err := ss.Post().GetPostIdBeforeTime(channelId, o2a.CreateAt)
|
||||
rPostId3, err := ss.Post().GetPostIdBeforeTime(channelId, o2a.CreateAt, false)
|
||||
require.Equal(t, rPostId3, o2.Id, "should return before post o2")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPostId3, err = ss.Post().GetPostIdAfterTime(channelId, o2a.CreateAt)
|
||||
rPostId3, err = ss.Post().GetPostIdAfterTime(channelId, o2a.CreateAt, false)
|
||||
require.Empty(t, rPostId3, "should return no post")
|
||||
require.NoError(t, err)
|
||||
|
||||
rPost3, err := ss.Post().GetPostAfterTime(channelId, o2a.CreateAt)
|
||||
rPost3, err := ss.Post().GetPostAfterTime(channelId, o2a.CreateAt, false)
|
||||
require.Empty(t, rPost3, "should return no post")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -4636,10 +4636,10 @@ func (s *TimerLayerPostStore) GetParentsForExportAfter(limit int, afterID string
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64) (*model.Post, error) {
|
||||
func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostAfterTime(channelID, time, collapsedThreads)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -4652,10 +4652,10 @@ func (s *TimerLayerPostStore) GetPostAfterTime(channelID string, time int64) (*m
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (string, error) {
|
||||
func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdAfterTime(channelID, time, collapsedThreads)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
@@ -4668,10 +4668,10 @@ func (s *TimerLayerPostStore) GetPostIdAfterTime(channelID string, time int64) (
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetPostIdBeforeTime(channelID string, time int64) (string, error) {
|
||||
func (s *TimerLayerPostStore) GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, error) {
|
||||
start := timemodule.Now()
|
||||
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time)
|
||||
result, err := s.PostStore.GetPostIdBeforeTime(channelID, time, collapsedThreads)
|
||||
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user