Don't fetch Mirror when it's migrating (#19588)

- 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 #19585
- Regression: #19295

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
tokarchuk/v1.17
Gusted 3 years ago committed by GitHub
parent b7abb31b7b
commit 982b726b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      models/task.go
  2. 11
      modules/context/repo.go

@ -181,6 +181,14 @@ func GetMigratingTask(repoID int64) (*Task, error) {
return &task, nil 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 // GetMigratingTaskByID returns the migrating task by repo's id
func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) { func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) {
task := Task{ task := Task{

@ -370,7 +370,15 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
ctx.Data["Permission"] = &ctx.Repo.Permission ctx.Data["Permission"] = &ctx.Repo.Permission
if repo.IsMirror { if repo.IsMirror {
var err error
// 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
}
if !hasTask {
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID) ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
if err != nil { if err != nil {
ctx.ServerError("GetMirrorByRepoID", err) ctx.ServerError("GetMirrorByRepoID", err)
@ -380,6 +388,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
ctx.Data["Mirror"] = ctx.Repo.Mirror ctx.Data["Mirror"] = ctx.Repo.Mirror
} }
}
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID) pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)
if err != nil { if err != nil {

Loading…
Cancel
Save