diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 6e3c6cfa32..068353faf9 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -1118,44 +1118,41 @@ func (s *SqlPostStore) GetPostsByIds(postIds []string) ([]*model.Post, *model.Ap return posts, nil } -func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - var posts []*model.PostForIndexing - _, err1 := s.GetSearchReplica().Select(&posts, - `SELECT - PostsQuery.*, Channels.TeamId, ParentPosts.CreateAt ParentCreateAt - FROM ( - SELECT - * - FROM - Posts - WHERE - Posts.CreateAt >= :StartTime - AND - Posts.CreateAt < :EndTime - ORDER BY - CreateAt ASC - LIMIT - 1000 - ) - AS - PostsQuery - LEFT JOIN - Channels - ON - PostsQuery.ChannelId = Channels.Id - LEFT JOIN - Posts ParentPosts - ON - PostsQuery.RootId = ParentPosts.Id`, - map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumPosts": limit}) +func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *model.AppError) { + var posts []*model.PostForIndexing + _, err := s.GetSearchReplica().Select(&posts, + `SELECT + PostsQuery.*, Channels.TeamId, ParentPosts.CreateAt ParentCreateAt + FROM ( + SELECT + * + FROM + Posts + WHERE + Posts.CreateAt >= :StartTime + AND + Posts.CreateAt < :EndTime + ORDER BY + CreateAt ASC + LIMIT + 1000 + ) + AS + PostsQuery + LEFT JOIN + Channels + ON + PostsQuery.ChannelId = Channels.Id + LEFT JOIN + Posts ParentPosts + ON + PostsQuery.RootId = ParentPosts.Id`, + map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumPosts": limit}) - if err1 != nil { - result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err1.Error(), http.StatusInternalServerError) - } else { - result.Data = posts - } - }) + if err != nil { + return nil, model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err.Error(), http.StatusInternalServerError) + } + return posts, nil } func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.StoreChannel { diff --git a/store/store.go b/store/store.go index afc998f62b..59753ed528 100644 --- a/store/store.go +++ b/store/store.go @@ -234,7 +234,7 @@ type PostStore interface { GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) Overwrite(post *model.Post) (*model.Post, *model.AppError) GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError) - GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel + GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *model.AppError) PermanentDeleteBatch(endTime int64, limit int64) StoreChannel GetOldest() StoreChannel GetMaxPostSize() int diff --git a/store/storetest/mocks/PostStore.go b/store/storetest/mocks/PostStore.go index 76a5e8812b..f44afef70c 100644 --- a/store/storetest/mocks/PostStore.go +++ b/store/storetest/mocks/PostStore.go @@ -327,19 +327,28 @@ func (_m *PostStore) GetPostsAfter(channelId string, postId string, numPosts int } // GetPostsBatchForIndexing provides a mock function with given fields: startTime, endTime, limit -func (_m *PostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel { +func (_m *PostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *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.PostForIndexing + if rf, ok := ret.Get(0).(func(int64, int64, int) []*model.PostForIndexing); ok { r0 = rf(startTime, endTime, limit) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).([]*model.PostForIndexing) } } - 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 } // GetPostsBefore provides a mock function with given fields: channelId, postId, numPosts, offset diff --git a/store/storetest/post_store.go b/store/storetest/post_store.go index 3d03a00ebd..1d232ee137 100644 --- a/store/storetest/post_store.go +++ b/store/storetest/post_store.go @@ -1979,7 +1979,9 @@ func testPostStoreGetPostsBatchForIndexing(t *testing.T, ss store.Store) { o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ" o3 = (<-ss.Post().Save(o3)).Data.(*model.Post) - if r := store.Must(ss.Post().GetPostsBatchForIndexing(o1.CreateAt, model.GetMillis()+100000, 100)).([]*model.PostForIndexing); len(r) != 3 { + if r, err := ss.Post().GetPostsBatchForIndexing(o1.CreateAt, model.GetMillis()+100000, 100); err != nil { + t.Fatal(err) + } else if len(r) != 3 { t.Fatalf("Expected 3 posts in results. Got %v", len(r)) } else { for _, p := range r {