mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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
This commit is contained in:
committed by
Jesús Espino
parent
c431a686b3
commit
b4d444319b
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user