[MM-53339] import: dont miss out reactions from replies (#29060)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3da77f2f05
Коммит
0e6ec05d5c
@@ -1369,10 +1369,17 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type postAndReactions struct {
|
||||||
|
post *model.Post
|
||||||
|
reactions *[]imports.ReactionImportData
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
postsWithData = []postAndData{}
|
postsWithData = []postAndData{}
|
||||||
postsForCreateList = []*model.Post{}
|
postsForCreateList = []*model.Post{}
|
||||||
postsForOverwriteList = []*model.Post{}
|
postsForOverwriteList = []*model.Post{}
|
||||||
|
reactionsForCreateMap = make(map[string]postAndReactions)
|
||||||
|
interimReactionsMap = map[int64]*[]imports.ReactionImportData{}
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, replyData := range data {
|
for _, replyData := range data {
|
||||||
@@ -1428,14 +1435,25 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
|
|||||||
|
|
||||||
if reply.Id == "" {
|
if reply.Id == "" {
|
||||||
postsForCreateList = append(postsForCreateList, reply)
|
postsForCreateList = append(postsForCreateList, reply)
|
||||||
|
if replyData.Reactions != nil && len(*replyData.Reactions) > 0 {
|
||||||
|
// although createAt is not unique, I think it is safe to
|
||||||
|
// assume that it could be near-unique especially for the same thread.
|
||||||
|
// If this assumption fails, the last reactions would be used for the
|
||||||
|
// posts that share same createAt value.
|
||||||
|
interimReactionsMap[reply.CreateAt] = replyData.Reactions
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
postsForOverwriteList = append(postsForOverwriteList, reply)
|
postsForOverwriteList = append(postsForOverwriteList, reply)
|
||||||
|
if replyData.Reactions != nil && len(*replyData.Reactions) > 0 {
|
||||||
|
reactionsForCreateMap[reply.Id] = postAndReactions{post: reply, reactions: replyData.Reactions}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
postsWithData = append(postsWithData, postAndData{post: reply, replyData: &replyData})
|
postsWithData = append(postsWithData, postAndData{post: reply, replyData: &replyData})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(postsForCreateList) > 0 {
|
if len(postsForCreateList) > 0 {
|
||||||
if _, _, err := a.Srv().Store().Post().SaveMultiple(postsForCreateList); err != nil {
|
postsCreated, _, err := a.Srv().Store().Post().SaveMultiple(postsForCreateList)
|
||||||
|
if err != nil {
|
||||||
var appErr *model.AppError
|
var appErr *model.AppError
|
||||||
var invErr *store.ErrInvalidInput
|
var invErr *store.ErrInvalidInput
|
||||||
switch {
|
switch {
|
||||||
@@ -1447,12 +1465,28 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
|
|||||||
return model.NewAppError("importReplies", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
return model.NewAppError("importReplies", "app.post.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, created := range postsCreated {
|
||||||
|
reactions, ok := interimReactionsMap[created.CreateAt]
|
||||||
|
if !ok || reactions == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
reactionsForCreateMap[created.Id] = postAndReactions{post: created, reactions: reactions}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, _, nErr := a.Srv().Store().Post().OverwriteMultiple(postsForOverwriteList); nErr != nil {
|
if _, _, nErr := a.Srv().Store().Post().OverwriteMultiple(postsForOverwriteList); nErr != nil {
|
||||||
return model.NewAppError("importReplies", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
return model.NewAppError("importReplies", "app.post.overwrite.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, postAndReactions := range reactionsForCreateMap {
|
||||||
|
for _, reaction := range *postAndReactions.reactions {
|
||||||
|
if err := a.importReaction(&reaction, postAndReactions.post); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, postWithData := range postsWithData {
|
for _, postWithData := range postsWithData {
|
||||||
a.updateFileInfoWithPostId(rctx, postWithData.post)
|
a.updateFileInfoWithPostId(rctx, postWithData.post)
|
||||||
|
|
||||||
|
|||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Ссылка в новой задаче
Block a user