MM-15864 - Made Post.GetRepliesForExport sync (#11046)
* Changed Post.GetRepliesForExport to be sync * Removed else, and renamed err * renamed result variable to replyPosts
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
6a42ad2af5
Коммит
2d14eef6c7
@@ -379,14 +379,12 @@ func (a *App) ExportAllPosts(writer io.Writer) *model.AppError {
|
|||||||
func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppError) {
|
func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppError) {
|
||||||
var replies []ReplyImportData
|
var replies []ReplyImportData
|
||||||
|
|
||||||
result := <-a.Srv.Store.Post().GetRepliesForExport(postId)
|
replyPosts, err := a.Srv.Store.Post().GetRepliesForExport(postId)
|
||||||
|
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
replyPosts := result.Data.([]*model.ReplyForExport)
|
|
||||||
|
|
||||||
for _, reply := range replyPosts {
|
for _, reply := range replyPosts {
|
||||||
replyImportObject := ImportReplyFromPost(reply)
|
replyImportObject := ImportReplyFromPost(reply)
|
||||||
if reply.HasReactions == true {
|
if reply.HasReactions == true {
|
||||||
|
|||||||
@@ -1293,30 +1293,29 @@ func (s *SqlPostStore) GetParentsForExportAfter(limit int, afterId string) ([]*m
|
|||||||
return posts, nil
|
return posts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetRepliesForExport(parentId string) store.StoreChannel {
|
func (s *SqlPostStore) GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError) {
|
||||||
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})
|
|
||||||
|
|
||||||
if err1 != nil {
|
var posts []*model.ReplyForExport
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetAllAfterForExport", "store.sql_post.get_posts.app_error", nil, err1.Error(), http.StatusInternalServerError)
|
_, err := s.GetSearchReplica().Select(&posts, `
|
||||||
} else {
|
SELECT
|
||||||
result.Data = posts
|
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) {
|
func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError) {
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ type PostStore interface {
|
|||||||
GetOldest() StoreChannel
|
GetOldest() StoreChannel
|
||||||
GetMaxPostSize() int
|
GetMaxPostSize() int
|
||||||
GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, *model.AppError)
|
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)
|
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
|
// 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)
|
ret := _m.Called(parentId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.ReplyForExport
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.ReplyForExport); ok {
|
||||||
r0 = rf(parentId)
|
r0 = rf(parentId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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
|
// 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.RootId = p1.Id
|
||||||
p2 = (<-ss.Post().Save(p2)).Data.(*model.Post)
|
p2 = (<-ss.Post().Save(p2)).Data.(*model.Post)
|
||||||
|
|
||||||
r1 := <-ss.Post().GetRepliesForExport(p1.Id)
|
r1, err := ss.Post().GetRepliesForExport(p1.Id)
|
||||||
assert.Nil(t, r1.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
d1 := r1.Data.([]*model.ReplyForExport)
|
assert.Len(t, r1, 1)
|
||||||
assert.Len(t, d1, 1)
|
|
||||||
|
|
||||||
reply1 := d1[0]
|
reply1 := r1[0]
|
||||||
assert.Equal(t, reply1.Id, p2.Id)
|
assert.Equal(t, reply1.Id, p2.Id)
|
||||||
assert.Equal(t, reply1.Message, p2.Message)
|
assert.Equal(t, reply1.Message, p2.Message)
|
||||||
assert.Equal(t, reply1.Username, u1.Username)
|
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)
|
_, err = ss.User().Update(&u1, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
r1 = <-ss.Post().GetRepliesForExport(p1.Id)
|
r1, err = ss.Post().GetRepliesForExport(p1.Id)
|
||||||
assert.Nil(t, r1.Err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
d1 = r1.Data.([]*model.ReplyForExport)
|
assert.Len(t, r1, 1)
|
||||||
assert.Len(t, d1, 1)
|
|
||||||
|
|
||||||
reply1 = d1[0]
|
reply1 = r1[0]
|
||||||
assert.Equal(t, reply1.Id, p2.Id)
|
assert.Equal(t, reply1.Id, p2.Id)
|
||||||
assert.Equal(t, reply1.Message, p2.Message)
|
assert.Equal(t, reply1.Message, p2.Message)
|
||||||
assert.Equal(t, reply1.Username, u1.Username)
|
assert.Equal(t, reply1.Username, u1.Username)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user