Skip to content

Commit

Permalink
Don't fetch Mirror when it's migrating (go-gitea#19588)
Browse files Browse the repository at this point in the history
- When a repository is still being migrated, don't try to fetch the
Mirror from the database. Instead skip it. This allows to visit
repositories that are still being migrated and were configured to be
mirrored.
- Resolves go-gitea#19585
- Regression: go-gitea#19295

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
2 people authored and AbdulrhmnGhanem committed Aug 23, 2022
1 parent baf6cc4 commit 61a8b48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 8 additions & 0 deletions models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ func GetMigratingTask(repoID int64) (*Task, error) {
return &task, nil
}

// HasMigratingTask returns if migrating task exist for repo.
func HasMigratingTask(repoID int64) (bool, error) {
return db.GetEngine(db.DefaultContext).Exist(&Task{
RepoID: repoID,
Type: structs.TaskTypeMigrateRepo,
})
}

// GetMigratingTaskByID returns the migrating task by repo's id
func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) {
task := Task{
Expand Down
19 changes: 14 additions & 5 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,24 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
ctx.Data["Permission"] = &ctx.Repo.Permission

if repo.IsMirror {
var err error
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)

// Check if there's a migrating task.
// If it does exist, don't fetch the Mirror from the database as it doesn't exist yet.
hasTask, err := models.HasMigratingTask(repo.ID)
if err != nil {
ctx.ServerError("GetMirrorByRepoID", err)
return
}
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
ctx.Data["Mirror"] = ctx.Repo.Mirror
if !hasTask {
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
if err != nil {
ctx.ServerError("GetMirrorByRepoID", err)
return
}
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
ctx.Data["Mirror"] = ctx.Repo.Mirror
}
}

pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)
Expand Down

0 comments on commit 61a8b48

Please sign in to comment.