[MM-25714] Keeps track of the import lines of the posts while importing to report the right line on error (#14752)
* [MM-25714] Keeps track of the import lines of the posts while importing to report the right line on error * Adding review comments * Reverse the order of the error and error line params
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ea06c291df
Коммит
6cd898fab7
@@ -30,31 +30,31 @@ func stopOnError(err LineImportWorkerError) bool {
|
||||
}
|
||||
|
||||
func (a *App) bulkImportWorker(dryRun bool, wg *sync.WaitGroup, lines <-chan LineImportWorkerData, errors chan<- LineImportWorkerError) {
|
||||
posts := []*PostImportData{}
|
||||
directPosts := []*DirectPostImportData{}
|
||||
postLines := []LineImportWorkerData{}
|
||||
directPostLines := []LineImportWorkerData{}
|
||||
for line := range lines {
|
||||
switch {
|
||||
case line.LineImportData.Type == "post":
|
||||
posts = append(posts, line.Post)
|
||||
postLines = append(postLines, line)
|
||||
if line.Post == nil {
|
||||
errors <- LineImportWorkerError{model.NewAppError("BulkImport", "app.import.import_line.null_post.error", nil, "", http.StatusBadRequest), line.LineNumber}
|
||||
}
|
||||
if len(posts) >= importMultiplePostsThreshold {
|
||||
if err := a.importMultiplePosts(posts, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, line.LineNumber}
|
||||
if len(postLines) >= importMultiplePostsThreshold {
|
||||
if errLine, err := a.importMultiplePostLines(postLines, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, errLine}
|
||||
}
|
||||
posts = []*PostImportData{}
|
||||
postLines = []LineImportWorkerData{}
|
||||
}
|
||||
case line.LineImportData.Type == "direct_post":
|
||||
directPosts = append(directPosts, line.DirectPost)
|
||||
directPostLines = append(directPostLines, line)
|
||||
if line.DirectPost == nil {
|
||||
errors <- LineImportWorkerError{model.NewAppError("BulkImport", "app.import.import_line.null_direct_post.error", nil, "", http.StatusBadRequest), line.LineNumber}
|
||||
}
|
||||
if len(directPosts) >= importMultiplePostsThreshold {
|
||||
if err := a.importMultipleDirectPosts(directPosts, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, line.LineNumber}
|
||||
if len(directPostLines) >= importMultiplePostsThreshold {
|
||||
if errLine, err := a.importMultipleDirectPostLines(directPostLines, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, errLine}
|
||||
}
|
||||
directPosts = []*DirectPostImportData{}
|
||||
directPostLines = []LineImportWorkerData{}
|
||||
}
|
||||
default:
|
||||
if err := a.importLine(line.LineImportData, dryRun); err != nil {
|
||||
@@ -63,14 +63,14 @@ func (a *App) bulkImportWorker(dryRun bool, wg *sync.WaitGroup, lines <-chan Lin
|
||||
}
|
||||
}
|
||||
|
||||
if len(posts) > 0 {
|
||||
if err := a.importMultiplePosts(posts, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, 0}
|
||||
if len(postLines) > 0 {
|
||||
if errLine, err := a.importMultiplePostLines(postLines, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, errLine}
|
||||
}
|
||||
}
|
||||
if len(directPosts) > 0 {
|
||||
if err := a.importMultipleDirectPosts(directPosts, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, 0}
|
||||
if len(directPostLines) > 0 {
|
||||
if errLine, err := a.importMultipleDirectPostLines(directPostLines, dryRun); err != nil {
|
||||
errors <- LineImportWorkerError{err, errLine}
|
||||
}
|
||||
}
|
||||
wg.Done()
|
||||
|
||||
Ссылка в новой задаче
Block a user