0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-26 14:54:26 +01:00

Add SyncTags to uploader interface (#9326)

* Add sync tags to interface

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Fix revive

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser 2019-12-11 18:20:11 -06:00 committed by Lunny Xiao
parent 3bf5a07537
commit 382936a668
3 changed files with 16 additions and 17 deletions

View file

@ -11,7 +11,8 @@ type Uploader interface {
CreateRepo(repo *Repository, opts MigrateOptions) error CreateRepo(repo *Repository, opts MigrateOptions) error
CreateTopics(topic ...string) error CreateTopics(topic ...string) error
CreateMilestones(milestones ...*Milestone) error CreateMilestones(milestones ...*Milestone) error
CreateReleases(syncTags bool, releases ...*Release) error CreateReleases(releases ...*Release) error
SyncTags() error
CreateLabels(labels ...*Label) error CreateLabels(labels ...*Label) error
CreateIssues(issues ...*Issue) error CreateIssues(issues ...*Issue) error
CreateComments(comments ...*Comment) error CreateComments(comments ...*Comment) error

View file

@ -201,7 +201,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
} }
// CreateReleases creates releases // CreateReleases creates releases
func (g *GiteaLocalUploader) CreateReleases(syncTags bool, releases ...*base.Release) error { func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
var rels = make([]*models.Release, 0, len(releases)) var rels = make([]*models.Release, 0, len(releases))
for _, release := range releases { for _, release := range releases {
var rel = models.Release{ var rel = models.Release{
@ -288,16 +288,13 @@ func (g *GiteaLocalUploader) CreateReleases(syncTags bool, releases ...*base.Rel
rels = append(rels, &rel) rels = append(rels, &rel)
} }
if err := models.InsertReleases(rels...); err != nil {
return err
}
if syncTags { return models.InsertReleases(rels...)
// sync tags to releases in database }
// SyncTags syncs releases with tags in the database
func (g *GiteaLocalUploader) SyncTags() error {
return models.SyncReleasesWithTags(g.repo, g.gitRepo) return models.SyncReleasesWithTags(g.repo, g.gitRepo)
}
return nil
} }
// CreateIssues creates issues // CreateIssues creates issues

View file

@ -161,20 +161,21 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
} }
relBatchSize := uploader.MaxBatchInsertSize("release") relBatchSize := uploader.MaxBatchInsertSize("release")
syncTags := false
for len(releases) > 0 { for len(releases) > 0 {
if len(releases) <= relBatchSize {
if len(releases) < relBatchSize { if len(releases) < relBatchSize {
relBatchSize = len(releases) relBatchSize = len(releases)
} }
syncTags = true
}
if err := uploader.CreateReleases(syncTags, releases[:relBatchSize]...); err != nil { if err := uploader.CreateReleases(releases[:relBatchSize]...); err != nil {
return err return err
} }
releases = releases[relBatchSize:] releases = releases[relBatchSize:]
} }
// Once all releases (if any) are inserted, sync any remaining non-release tags
if err := uploader.SyncTags(); err != nil {
return err
}
} }
var commentBatchSize = uploader.MaxBatchInsertSize("comment") var commentBatchSize = uploader.MaxBatchInsertSize("comment")