[MM-53339] import: dont miss out reactions from replies (#29060)

Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2024-11-15 09:45:14 +01:00
коммит произвёл GitHub
родитель 3da77f2f05
Коммит 0e6ec05d5c
2 изменённых файлов: 772 добавлений и 564 удалений

Просмотреть файл

@@ -1369,10 +1369,17 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
return err
}
type postAndReactions struct {
post *model.Post
reactions *[]imports.ReactionImportData
}
var (
postsWithData = []postAndData{}
postsForCreateList = []*model.Post{}
postsForOverwriteList = []*model.Post{}
reactionsForCreateMap = make(map[string]postAndReactions)
interimReactionsMap = map[int64]*[]imports.ReactionImportData{}
)
for _, replyData := range data {
@@ -1428,14 +1435,25 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
if reply.Id == "" {
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 {
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})
}
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 invErr *store.ErrInvalidInput
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)
}
}
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 {
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 {
a.updateFileInfoWithPostId(rctx, postWithData.post)

Разница между файлами не показана из-за своего большого размера Загрузить разницу