diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-29 21:38:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-29 21:38:22 +0800 |
commit | 462284e2f5768cf04d71c7abd8c01eef20cff73d (patch) | |
tree | 10d970a11d6c604cbe99cbd1e89c6dda983d6ac7 /modules/migrations/migrate.go | |
parent | e463bdaf8d995d0b399c1848a780ac5aa8798f0d (diff) | |
download | gitea-462284e2f5768cf04d71c7abd8c01eef20cff73d.tar.gz gitea-462284e2f5768cf04d71c7abd8c01eef20cff73d.zip |
Use batch insert on migrating repository to make the process faster (#7050)
* Use batch insert on migrating repository to make the process faster
* fix lint
* fix tests
* fix comments
Diffstat (limited to 'modules/migrations/migrate.go')
-rw-r--r-- | modules/migrations/migrate.go | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index 4b1229f949..3a4e6b2dbe 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -91,10 +91,8 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts return err } - for _, milestone := range milestones { - if err := uploader.CreateMilestone(milestone); err != nil { - return err - } + if err := uploader.CreateMilestones(milestones...); err != nil { + return err } } @@ -105,10 +103,8 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts return err } - for _, label := range labels { - if err := uploader.CreateLabel(label); err != nil { - return err - } + if err := uploader.CreateLabels(labels...); err != nil { + return err } } @@ -119,10 +115,8 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts return err } - for _, release := range releases { - if err := uploader.CreateRelease(release); err != nil { - return err - } + if err := uploader.CreateReleases(releases...); err != nil { + return err } } @@ -137,15 +131,18 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if !opts.IgnoreIssueAuthor { issue.Content = fmt.Sprintf("Author: @%s \n\n%s", issue.PosterName, issue.Content) } + } - if err := uploader.CreateIssue(issue); err != nil { - return err - } + if err := uploader.CreateIssues(issues...); err != nil { + return err + } - if !opts.Comments { - continue - } + if !opts.Comments { + continue + } + var allComments = make([]*base.Comment, 0, 100) + for _, issue := range issues { comments, err := downloader.GetComments(issue.Number) if err != nil { return err @@ -154,9 +151,20 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if !opts.IgnoreIssueAuthor { comment.Content = fmt.Sprintf("Author: @%s \n\n%s", comment.PosterName, comment.Content) } - if err := uploader.CreateComment(issue.Number, comment); err != nil { + } + allComments = append(allComments, comments...) + + if len(allComments) >= 100 { + if err := uploader.CreateComments(allComments...); err != nil { return err } + allComments = make([]*base.Comment, 0, 100) + } + } + + if len(allComments) > 0 { + if err := uploader.CreateComments(allComments...); err != nil { + return err } } @@ -178,13 +186,17 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if !opts.IgnoreIssueAuthor { pr.Content = fmt.Sprintf("Author: @%s \n\n%s", pr.PosterName, pr.Content) } - if err := uploader.CreatePullRequest(pr); err != nil { - return err - } - if !opts.Comments { - continue - } + } + if err := uploader.CreatePullRequests(prs...); err != nil { + return err + } + if !opts.Comments { + continue + } + + var allComments = make([]*base.Comment, 0, 100) + for _, pr := range prs { comments, err := downloader.GetComments(pr.Number) if err != nil { return err @@ -193,11 +205,23 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if !opts.IgnoreIssueAuthor { comment.Content = fmt.Sprintf("Author: @%s \n\n%s", comment.PosterName, comment.Content) } - if err := uploader.CreateComment(pr.Number, comment); err != nil { + } + + allComments = append(allComments, comments...) + + if len(allComments) >= 100 { + if err := uploader.CreateComments(allComments...); err != nil { return err } + allComments = make([]*base.Comment, 0, 100) } } + if len(allComments) > 0 { + if err := uploader.CreateComments(allComments...); err != nil { + return err + } + } + if len(prs) < 100 { break } |