mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-15864 - Made Post.GetRepliesForExport sync (#11046)
* Changed Post.GetRepliesForExport to be sync * Removed else, and renamed err * renamed result variable to replyPosts
This commit is contained in:
committed by
Jesse Hallam
parent
6a42ad2af5
commit
2d14eef6c7
@@ -379,14 +379,12 @@ func (a *App) ExportAllPosts(writer io.Writer) *model.AppError {
|
||||
func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppError) {
|
||||
var replies []ReplyImportData
|
||||
|
||||
result := <-a.Srv.Store.Post().GetRepliesForExport(postId)
|
||||
replyPosts, err := a.Srv.Store.Post().GetRepliesForExport(postId)
|
||||
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
replyPosts := result.Data.([]*model.ReplyForExport)
|
||||
|
||||
for _, reply := range replyPosts {
|
||||
replyImportObject := ImportReplyFromPost(reply)
|
||||
if reply.HasReactions == true {
|
||||
|
||||
@@ -1293,30 +1293,29 @@ func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string) ([]*m
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetRepliesForExport(parentId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var posts []*model.ReplyForExport
|
||||
_, err1 := s.GetSearchReplica().Select(&posts, `
|
||||
SELECT
|
||||
Posts.*,
|
||||
Users.Username as Username
|
||||
FROM
|
||||
Posts
|
||||
INNER JOIN
|
||||
Users ON Posts.UserId = Users.Id
|
||||
WHERE
|
||||
Posts.ParentId = :ParentId
|
||||
AND Posts.DeleteAt = 0
|
||||
ORDER BY
|
||||
Posts.Id`,
|
||||
map[string]interface{}{"ParentId": parentId})
|
||||
func (s *SqlPostStore) GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError) {
|
||||
|
||||
if err1 != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.GetAllAfterForExport", "store.sql_post.get_posts.app_error", nil, err1.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = posts
|
||||
}
|
||||
})
|
||||
var posts []*model.ReplyForExport
|
||||
_, err := s.GetSearchReplica().Select(&posts, `
|
||||
SELECT
|
||||
Posts.*,
|
||||
Users.Username as Username
|
||||
FROM
|
||||
Posts
|
||||
INNER JOIN
|
||||
Users ON Posts.UserId = Users.Id
|
||||
WHERE
|
||||
Posts.ParentId = :ParentId
|
||||
AND Posts.DeleteAt = 0
|
||||
ORDER BY
|
||||
Posts.Id`,
|
||||
map[string]interface{}{"ParentId": parentId})
|
||||
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("SqlPostStore.GetAllAfterForExport", "store.sql_post.get_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError) {
|
||||
|
||||
@@ -239,7 +239,7 @@ type PostStore interface {
|
||||
GetOldest() StoreChannel
|
||||
GetMaxPostSize() int
|
||||
GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, *model.AppError)
|
||||
GetRepliesForExport(parentId string) StoreChannel
|
||||
GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError)
|
||||
GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError)
|
||||
}
|
||||
|
||||
|
||||
@@ -416,19 +416,28 @@ func (_m *PostStore) GetPostsSince(channelId string, time int64, allowFromCache
|
||||
}
|
||||
|
||||
// GetRepliesForExport provides a mock function with given fields: parentId
|
||||
func (_m *PostStore) GetRepliesForExport(parentId string) store.StoreChannel {
|
||||
func (_m *PostStore) GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError) {
|
||||
ret := _m.Called(parentId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 []*model.ReplyForExport
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.ReplyForExport); ok {
|
||||
r0 = rf(parentId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.ReplyForExport)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(parentId)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSingle provides a mock function with given fields: id
|
||||
|
||||
@@ -2173,13 +2173,12 @@ func testPostStoreGetRepliesForExport(t *testing.T, ss store.Store) {
|
||||
p2.RootId = p1.Id
|
||||
p2 = (<-ss.Post().Save(p2)).Data.(*model.Post)
|
||||
|
||||
r1 := <-ss.Post().GetRepliesForExport(p1.Id)
|
||||
assert.Nil(t, r1.Err)
|
||||
r1, err := ss.Post().GetRepliesForExport(p1.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
d1 := r1.Data.([]*model.ReplyForExport)
|
||||
assert.Len(t, d1, 1)
|
||||
assert.Len(t, r1, 1)
|
||||
|
||||
reply1 := d1[0]
|
||||
reply1 := r1[0]
|
||||
assert.Equal(t, reply1.Id, p2.Id)
|
||||
assert.Equal(t, reply1.Message, p2.Message)
|
||||
assert.Equal(t, reply1.Username, u1.Username)
|
||||
@@ -2189,13 +2188,12 @@ func testPostStoreGetRepliesForExport(t *testing.T, ss store.Store) {
|
||||
_, err = ss.User().Update(&u1, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
r1 = <-ss.Post().GetRepliesForExport(p1.Id)
|
||||
assert.Nil(t, r1.Err)
|
||||
r1, err = ss.Post().GetRepliesForExport(p1.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
d1 = r1.Data.([]*model.ReplyForExport)
|
||||
assert.Len(t, d1, 1)
|
||||
assert.Len(t, r1, 1)
|
||||
|
||||
reply1 = d1[0]
|
||||
reply1 = r1[0]
|
||||
assert.Equal(t, reply1.Id, p2.Id)
|
||||
assert.Equal(t, reply1.Message, p2.Message)
|
||||
assert.Equal(t, reply1.Username, u1.Username)
|
||||
|
||||
Reference in New Issue
Block a user