GH-10968 Migrate 'Post.GetPostsBatchForIndexing' to Sync by default (#11031)
* GH-10968 Migrate 'Post.GetPostsBatchForIndexing' to Sync by default * Fix indentation and check return value
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
c431a686b3
Коммит
b4d444319b
@@ -1118,44 +1118,41 @@ func (s *SqlPostStore) GetPostsByIds(postIds []string) ([]*model.Post, *model.Ap
|
|||||||
return posts, nil
|
return posts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) store.StoreChannel {
|
func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var posts []*model.PostForIndexing
|
||||||
var posts []*model.PostForIndexing
|
_, err := s.GetSearchReplica().Select(&posts,
|
||||||
_, err1 := s.GetSearchReplica().Select(&posts,
|
`SELECT
|
||||||
`SELECT
|
PostsQuery.*, Channels.TeamId, ParentPosts.CreateAt ParentCreateAt
|
||||||
PostsQuery.*, Channels.TeamId, ParentPosts.CreateAt ParentCreateAt
|
FROM (
|
||||||
FROM (
|
SELECT
|
||||||
SELECT
|
*
|
||||||
*
|
FROM
|
||||||
FROM
|
Posts
|
||||||
Posts
|
WHERE
|
||||||
WHERE
|
Posts.CreateAt >= :StartTime
|
||||||
Posts.CreateAt >= :StartTime
|
AND
|
||||||
AND
|
Posts.CreateAt < :EndTime
|
||||||
Posts.CreateAt < :EndTime
|
ORDER BY
|
||||||
ORDER BY
|
CreateAt ASC
|
||||||
CreateAt ASC
|
LIMIT
|
||||||
LIMIT
|
1000
|
||||||
1000
|
)
|
||||||
)
|
AS
|
||||||
AS
|
PostsQuery
|
||||||
PostsQuery
|
LEFT JOIN
|
||||||
LEFT JOIN
|
Channels
|
||||||
Channels
|
ON
|
||||||
ON
|
PostsQuery.ChannelId = Channels.Id
|
||||||
PostsQuery.ChannelId = Channels.Id
|
LEFT JOIN
|
||||||
LEFT JOIN
|
Posts ParentPosts
|
||||||
Posts ParentPosts
|
ON
|
||||||
ON
|
PostsQuery.RootId = ParentPosts.Id`,
|
||||||
PostsQuery.RootId = ParentPosts.Id`,
|
map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumPosts": limit})
|
||||||
map[string]interface{}{"StartTime": startTime, "EndTime": endTime, "NumPosts": limit})
|
|
||||||
|
|
||||||
if err1 != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err1.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = posts
|
return posts, nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.StoreChannel {
|
func (s *SqlPostStore) PermanentDeleteBatch(endTime int64, limit int64) store.StoreChannel {
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ type PostStore interface {
|
|||||||
GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError)
|
GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError)
|
||||||
Overwrite(post *model.Post) (*model.Post, *model.AppError)
|
Overwrite(post *model.Post) (*model.Post, *model.AppError)
|
||||||
GetPostsByIds(postIds []string) ([]*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
|
PermanentDeleteBatch(endTime int64, limit int64) StoreChannel
|
||||||
GetOldest() StoreChannel
|
GetOldest() StoreChannel
|
||||||
GetMaxPostSize() int
|
GetMaxPostSize() int
|
||||||
|
|||||||
@@ -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
|
// 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)
|
ret := _m.Called(startTime, endTime, limit)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.PostForIndexing
|
||||||
if rf, ok := ret.Get(0).(func(int64, int64, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(int64, int64, int) []*model.PostForIndexing); ok {
|
||||||
r0 = rf(startTime, endTime, limit)
|
r0 = rf(startTime, endTime, limit)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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
|
// GetPostsBefore provides a mock function with given fields: channelId, postId, numPosts, offset
|
||||||
|
|||||||
@@ -1979,7 +1979,9 @@ func testPostStoreGetPostsBatchForIndexing(t *testing.T, ss store.Store) {
|
|||||||
o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ"
|
o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ"
|
||||||
o3 = (<-ss.Post().Save(o3)).Data.(*model.Post)
|
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))
|
t.Fatalf("Expected 3 posts in results. Got %v", len(r))
|
||||||
} else {
|
} else {
|
||||||
for _, p := range r {
|
for _, p := range r {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user