MM-15850/MM-15851 GetPosts Before/After sync by default (#11035)
Этот коммит содержится в:
24
app/post.go
24
app/post.go
@@ -667,34 +667,18 @@ func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsBeforePost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsBeforePost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Post().GetPostsBefore(channelId, postId, perPage, page*perPage)
|
return a.Srv.Store.Post().GetPostsBefore(channelId, postId, perPage, page*perPage)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.PostList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsAfterPost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsAfterPost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Post().GetPostsAfter(channelId, postId, perPage, page*perPage)
|
return a.Srv.Store.Post().GetPostsAfter(channelId, postId, perPage, page*perPage)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.PostList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, before bool) (*model.PostList, *model.AppError) {
|
func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, before bool) (*model.PostList, *model.AppError) {
|
||||||
var pchan store.StoreChannel
|
|
||||||
if before {
|
if before {
|
||||||
pchan = a.Srv.Store.Post().GetPostsBefore(channelId, postId, limit, offset)
|
return a.Srv.Store.Post().GetPostsBefore(channelId, postId, limit, offset)
|
||||||
} else {
|
|
||||||
pchan = a.Srv.Store.Post().GetPostsAfter(channelId, postId, limit, offset)
|
|
||||||
}
|
}
|
||||||
|
return a.Srv.Store.Post().GetPostsAfter(channelId, postId, limit, offset)
|
||||||
result := <-pchan
|
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.PostList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
|
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
|
||||||
|
|||||||
@@ -581,16 +581,15 @@ func (s *SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCach
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, limit int, offset int) store.StoreChannel {
|
func (s *SqlPostStore) GetPostsBefore(channelId string, postId string, limit int, offset int) (*model.PostList, *model.AppError) {
|
||||||
return s.getPostsAround(channelId, postId, limit, offset, true)
|
return s.getPostsAround(channelId, postId, limit, offset, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetPostsAfter(channelId string, postId string, limit int, offset int) store.StoreChannel {
|
func (s *SqlPostStore) GetPostsAfter(channelId string, postId string, limit int, offset int) (*model.PostList, *model.AppError) {
|
||||||
return s.getPostsAround(channelId, postId, limit, offset, false)
|
return s.getPostsAround(channelId, postId, limit, offset, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int, offset int, before bool) store.StoreChannel {
|
func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int, offset int, before bool) (*model.PostList, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
var direction string
|
var direction string
|
||||||
var sort string
|
var sort string
|
||||||
if before {
|
if before {
|
||||||
@@ -603,7 +602,7 @@ func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int
|
|||||||
|
|
||||||
var posts []*model.Post
|
var posts []*model.Post
|
||||||
var parents []*model.Post
|
var parents []*model.Post
|
||||||
_, err1 := s.GetReplica().Select(&posts,
|
_, err := s.GetReplica().Select(&posts,
|
||||||
`SELECT
|
`SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
@@ -616,7 +615,10 @@ func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int
|
|||||||
LIMIT :Limit
|
LIMIT :Limit
|
||||||
OFFSET :Offset`,
|
OFFSET :Offset`,
|
||||||
map[string]interface{}{"ChannelId": channelId, "PostId": postId, "Limit": limit, "Offset": offset})
|
map[string]interface{}{"ChannelId": channelId, "PostId": postId, "Limit": limit, "Offset": offset})
|
||||||
_, err2 := s.GetReplica().Select(&parents,
|
if err != nil {
|
||||||
|
return nil, model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
_, err = s.GetReplica().Select(&parents,
|
||||||
`SELECT
|
`SELECT
|
||||||
q2.*
|
q2.*
|
||||||
FROM
|
FROM
|
||||||
@@ -645,11 +647,9 @@ func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int
|
|||||||
ORDER BY CreateAt DESC`,
|
ORDER BY CreateAt DESC`,
|
||||||
map[string]interface{}{"ChannelId": channelId, "PostId": postId, "Limit": limit, "Offset": offset})
|
map[string]interface{}{"ChannelId": channelId, "PostId": postId, "Limit": limit, "Offset": offset})
|
||||||
|
|
||||||
if err1 != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get.app_error", nil, "channelId="+channelId+err1.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get_parent.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError)
|
||||||
} else if err2 != nil {
|
}
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get_parent.app_error", nil, "channelId="+channelId+err2.Error(), http.StatusInternalServerError)
|
|
||||||
} else {
|
|
||||||
list := model.NewPostList()
|
list := model.NewPostList()
|
||||||
|
|
||||||
// We need to flip the order if we selected backwards
|
// We need to flip the order if we selected backwards
|
||||||
@@ -669,10 +669,7 @@ func (s *SqlPostStore) getPostsAround(channelId string, postId string, limit int
|
|||||||
for _, p := range parents {
|
for _, p := range parents {
|
||||||
list.AddPost(p)
|
list.AddPost(p)
|
||||||
}
|
}
|
||||||
|
return list, nil
|
||||||
result.Data = list
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) store.StoreChannel {
|
func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) store.StoreChannel {
|
||||||
|
|||||||
@@ -221,8 +221,8 @@ type PostStore interface {
|
|||||||
GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||||
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
|
GetPostsBefore(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError)
|
||||||
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
|
GetPostsAfter(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError)
|
||||||
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
|
GetPostsSince(channelId string, time int64, allowFromCache bool) StoreChannel
|
||||||
GetEtag(channelId string, allowFromCache bool) string
|
GetEtag(channelId string, allowFromCache bool) string
|
||||||
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
||||||
|
|||||||
@@ -302,19 +302,28 @@ func (_m *PostStore) GetPosts(channelId string, offset int, limit int, allowFrom
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsAfter provides a mock function with given fields: channelId, postId, numPosts, offset
|
// GetPostsAfter provides a mock function with given fields: channelId, postId, numPosts, offset
|
||||||
func (_m *PostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
func (_m *PostStore) GetPostsAfter(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) {
|
||||||
ret := _m.Called(channelId, postId, numPosts, offset)
|
ret := _m.Called(channelId, postId, numPosts, offset)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.PostList
|
||||||
if rf, ok := ret.Get(0).(func(string, string, int, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, int, int) *model.PostList); ok {
|
||||||
r0 = rf(channelId, postId, numPosts, offset)
|
r0 = rf(channelId, postId, numPosts, offset)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.PostList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, int, int) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId, postId, numPosts, offset)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
|
// GetPostsBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
|
||||||
@@ -334,19 +343,28 @@ func (_m *PostStore) GetPostsBatchForIndexing(startTime int64, endTime int64, li
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsBefore provides a mock function with given fields: channelId, postId, numPosts, offset
|
// GetPostsBefore provides a mock function with given fields: channelId, postId, numPosts, offset
|
||||||
func (_m *PostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) store.StoreChannel {
|
func (_m *PostStore) GetPostsBefore(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) {
|
||||||
ret := _m.Called(channelId, postId, numPosts, offset)
|
ret := _m.Called(channelId, postId, numPosts, offset)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.PostList
|
||||||
if rf, ok := ret.Get(0).(func(string, string, int, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string, int, int) *model.PostList); ok {
|
||||||
r0 = rf(channelId, postId, numPosts, offset)
|
r0 = rf(channelId, postId, numPosts, offset)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.PostList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string, int, int) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId, postId, numPosts, offset)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPostsByIds provides a mock function with given fields: postIds
|
// GetPostsByIds provides a mock function with given fields: postIds
|
||||||
|
|||||||
@@ -731,19 +731,17 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("should not return anything before the first post", func(t *testing.T) {
|
t.Run("should not return anything before the first post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsBefore(channelId, posts[0].Id, 10, 0)
|
postList, err := ss.Post().GetPostsBefore(channelId, posts[0].Id, 10, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{}, postList.Order)
|
assert.Equal(t, []string{}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{}, postList.Posts)
|
assert.Equal(t, map[string]*model.Post{}, postList.Posts)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should return posts before a post", func(t *testing.T) {
|
t.Run("should return posts before a post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsBefore(channelId, posts[5].Id, 10, 0)
|
postList, err := ss.Post().GetPostsBefore(channelId, posts[5].Id, 10, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{posts[4].Id, posts[3].Id, posts[2].Id, posts[1].Id, posts[0].Id}, postList.Order)
|
assert.Equal(t, []string{posts[4].Id, posts[3].Id, posts[2].Id, posts[1].Id, posts[0].Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
posts[0].Id: posts[0],
|
posts[0].Id: posts[0],
|
||||||
@@ -755,10 +753,9 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should limit posts before", func(t *testing.T) {
|
t.Run("should limit posts before", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsBefore(channelId, posts[5].Id, 2, 0)
|
postList, err := ss.Post().GetPostsBefore(channelId, posts[5].Id, 2, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{posts[4].Id, posts[3].Id}, postList.Order)
|
assert.Equal(t, []string{posts[4].Id, posts[3].Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
posts[3].Id: posts[3],
|
posts[3].Id: posts[3],
|
||||||
@@ -767,19 +764,17 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should not return anything after the last post", func(t *testing.T) {
|
t.Run("should not return anything after the last post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsAfter(channelId, posts[len(posts)-1].Id, 10, 0)
|
postList, err := ss.Post().GetPostsAfter(channelId, posts[len(posts)-1].Id, 10, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{}, postList.Order)
|
assert.Equal(t, []string{}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{}, postList.Posts)
|
assert.Equal(t, map[string]*model.Post{}, postList.Posts)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should return posts after a post", func(t *testing.T) {
|
t.Run("should return posts after a post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsAfter(channelId, posts[5].Id, 10, 0)
|
postList, err := ss.Post().GetPostsAfter(channelId, posts[5].Id, 10, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{posts[9].Id, posts[8].Id, posts[7].Id, posts[6].Id}, postList.Order)
|
assert.Equal(t, []string{posts[9].Id, posts[8].Id, posts[7].Id, posts[6].Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
posts[6].Id: posts[6],
|
posts[6].Id: posts[6],
|
||||||
@@ -790,10 +785,9 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should limit posts after", func(t *testing.T) {
|
t.Run("should limit posts after", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsAfter(channelId, posts[5].Id, 2, 0)
|
postList, err := ss.Post().GetPostsAfter(channelId, posts[5].Id, 2, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{posts[7].Id, posts[6].Id}, postList.Order)
|
assert.Equal(t, []string{posts[7].Id, posts[6].Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
posts[6].Id: posts[6],
|
posts[6].Id: posts[6],
|
||||||
@@ -866,10 +860,9 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
post2.UpdateAt = post6.UpdateAt
|
post2.UpdateAt = post6.UpdateAt
|
||||||
|
|
||||||
t.Run("should return each post and thread before a post", func(t *testing.T) {
|
t.Run("should return each post and thread before a post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsBefore(channelId, post4.Id, 2, 0)
|
postList, err := ss.Post().GetPostsBefore(channelId, post4.Id, 2, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{post3.Id, post2.Id}, postList.Order)
|
assert.Equal(t, []string{post3.Id, post2.Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
post1.Id: post1,
|
post1.Id: post1,
|
||||||
@@ -881,10 +874,9 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should return each post and the root of each thread after a post", func(t *testing.T) {
|
t.Run("should return each post and the root of each thread after a post", func(t *testing.T) {
|
||||||
res := <-ss.Post().GetPostsAfter(channelId, post4.Id, 2, 0)
|
postList, err := ss.Post().GetPostsAfter(channelId, post4.Id, 2, 0)
|
||||||
assert.Nil(t, res.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
postList := res.Data.(*model.PostList)
|
|
||||||
assert.Equal(t, []string{post6.Id, post5.Id}, postList.Order)
|
assert.Equal(t, []string{post6.Id, post5.Id}, postList.Order)
|
||||||
assert.Equal(t, map[string]*model.Post{
|
assert.Equal(t, map[string]*model.Post{
|
||||||
post2.Id: post2,
|
post2.Id: post2,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user