Migrate "Post.GetPostsByIds" to Sync by default (#11034)
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
a57e042dab
Коммит
b26e5d444e
@@ -260,10 +260,9 @@ func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T)
|
|||||||
postId := files[0].PostId
|
postId := files[0].PostId
|
||||||
assert.NotNil(t, postId)
|
assert.NotNil(t, postId)
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.Post().GetPostsByIds([]string{postId}); result.Err != nil {
|
if posts, err := th.App.Srv.Store.Post().GetPostsByIds([]string{postId}); err != nil {
|
||||||
t.Fatal(result.Err.Error())
|
t.Fatal(err.Error())
|
||||||
} else {
|
} else {
|
||||||
posts := result.Data.([]*model.Post)
|
|
||||||
assert.Equal(t, len(posts), 1)
|
assert.Equal(t, len(posts), 1)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
assert.Contains(t, posts[0].FileIds, file.Id)
|
assert.Contains(t, posts[0].FileIds, file.Id)
|
||||||
|
|||||||
@@ -883,11 +883,11 @@ func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId strin
|
|||||||
// Get the posts
|
// Get the posts
|
||||||
postList := model.NewPostList()
|
postList := model.NewPostList()
|
||||||
if len(postIds) > 0 {
|
if len(postIds) > 0 {
|
||||||
presult := <-a.Srv.Store.Post().GetPostsByIds(postIds)
|
posts, err := a.Srv.Store.Post().GetPostsByIds(postIds)
|
||||||
if presult.Err != nil {
|
if err != nil {
|
||||||
return nil, presult.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, p := range presult.Data.([]*model.Post) {
|
for _, p := range posts {
|
||||||
if p.DeleteAt == 0 {
|
if p.DeleteAt == 0 {
|
||||||
postList.AddPost(p)
|
postList.AddPost(p)
|
||||||
postList.AddOrder(p.Id)
|
postList.AddOrder(p.Id)
|
||||||
|
|||||||
@@ -1105,22 +1105,19 @@ func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model
|
|||||||
return posts, nil
|
return posts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
func (s *SqlPostStore) GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
keys, params := MapStringsToQueryParams(postIds, "Post")
|
||||||
keys, params := MapStringsToQueryParams(postIds, "Post")
|
|
||||||
|
|
||||||
query := `SELECT * FROM Posts WHERE Id IN ` + keys + ` ORDER BY CreateAt DESC`
|
query := `SELECT * FROM Posts WHERE Id IN ` + keys + ` ORDER BY CreateAt DESC`
|
||||||
|
|
||||||
var posts []*model.Post
|
var posts []*model.Post
|
||||||
_, err := s.GetReplica().Select(&posts, query, params)
|
_, err := s.GetReplica().Select(&posts, query, params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprint(err))
|
mlog.Error(fmt.Sprint(err))
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetPostsByIds", "store.sql_post.get_posts_by_ids.app_error", nil, "", http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlPostStore.GetPostsByIds", "store.sql_post.get_posts_by_ids.app_error", nil, "", http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = posts
|
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) store.StoreChannel {
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ type PostStore interface {
|
|||||||
InvalidateLastPostTimeCache(channelId string)
|
InvalidateLastPostTimeCache(channelId string)
|
||||||
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) StoreChannel
|
GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError)
|
||||||
GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel
|
GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) StoreChannel
|
||||||
PermanentDeleteBatch(endTime int64, limit int64) StoreChannel
|
PermanentDeleteBatch(endTime int64, limit int64) StoreChannel
|
||||||
GetOldest() StoreChannel
|
GetOldest() StoreChannel
|
||||||
|
|||||||
@@ -350,19 +350,28 @@ func (_m *PostStore) GetPostsBefore(channelId string, postId string, numPosts in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsByIds provides a mock function with given fields: postIds
|
// GetPostsByIds provides a mock function with given fields: postIds
|
||||||
func (_m *PostStore) GetPostsByIds(postIds []string) store.StoreChannel {
|
func (_m *PostStore) GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError) {
|
||||||
ret := _m.Called(postIds)
|
ret := _m.Called(postIds)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Post
|
||||||
if rf, ok := ret.Get(0).(func([]string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func([]string) []*model.Post); ok {
|
||||||
r0 = rf(postIds)
|
r0 = rf(postIds)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).([]*model.Post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
|
||||||
|
r1 = rf(postIds)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsCreatedAt provides a mock function with given fields: channelId, time
|
// GetPostsCreatedAt provides a mock function with given fields: channelId, time
|
||||||
|
|||||||
@@ -1935,16 +1935,20 @@ func testPostStoreGetPostsByIds(t *testing.T, ss store.Store) {
|
|||||||
ro3.Id,
|
ro3.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ro4 := store.Must(ss.Post().GetPostsByIds(postIds)).([]*model.Post); len(ro4) != 3 {
|
if posts, err := ss.Post().GetPostsByIds(postIds); err != nil {
|
||||||
t.Fatalf("Expected 3 posts in results. Got %v", len(ro4))
|
t.Fatal(err)
|
||||||
|
} else if len(posts) != 3 {
|
||||||
|
t.Fatalf("Expected 3 posts in results. Got %v", len(posts))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ss.Post().Delete(ro1.Id, model.GetMillis(), ""); err != nil {
|
if err := ss.Post().Delete(ro1.Id, model.GetMillis(), ""); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ro5 := store.Must(ss.Post().GetPostsByIds(postIds)).([]*model.Post); len(ro5) != 3 {
|
if posts, err := ss.Post().GetPostsByIds(postIds); err != nil {
|
||||||
t.Fatalf("Expected 3 posts in results. Got %v", len(ro5))
|
t.Fatal(err)
|
||||||
|
} else if len(posts) != 3 {
|
||||||
|
t.Fatalf("Expected 3 posts in results. Got %v", len(posts))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user