Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migration releases (#9319) (#9326) #9328

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Only sync tags after all batches (#9319)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
  • Loading branch information
jolheiser committed Dec 12, 2019
commit e67edb74aeca16f9b2f7b9691911f08ecaad3df6
2 changes: 1 addition & 1 deletion modules/migrations/base/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Uploader interface {
CreateRepo(repo *Repository, opts MigrateOptions) error
CreateTopics(topic ...string) error
CreateMilestones(milestones ...*Milestone) error
CreateReleases(releases ...*Release) error
CreateReleases(syncTags bool, releases ...*Release) error
CreateLabels(labels ...*Label) error
CreateIssues(issues ...*Issue) error
CreateComments(comments ...*Comment) error
Expand Down
10 changes: 7 additions & 3 deletions modules/migrations/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
}

// CreateReleases creates releases
func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
func (g *GiteaLocalUploader) CreateReleases(syncTags bool, releases ...*base.Release) error {
var rels = make([]*models.Release, 0, len(releases))
for _, release := range releases {
var rel = models.Release{
Expand Down Expand Up @@ -292,8 +292,12 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
return err
}

// sync tags to releases in database
return models.SyncReleasesWithTags(g.repo, g.gitRepo)
if syncTags {
// sync tags to releases in database
return models.SyncReleasesWithTags(g.repo, g.gitRepo)
}

return nil
}

// CreateIssues creates issues
Expand Down
10 changes: 7 additions & 3 deletions modules/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
}

relBatchSize := uploader.MaxBatchInsertSize("release")
syncTags := false
for len(releases) > 0 {
if len(releases) < relBatchSize {
relBatchSize = len(releases)
if len(releases) <= relBatchSize {
if len(releases) < relBatchSize {
relBatchSize = len(releases)
}
syncTags = true
}

if err := uploader.CreateReleases(releases[:relBatchSize]...); err != nil {
if err := uploader.CreateReleases(syncTags, releases[:relBatchSize]...); err != nil {
return err
}
releases = releases[relBatchSize:]
Expand Down