From 77b38a8dd791d16a2f6b85f0c9a75f998393c363 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 2 May 2022 22:49:32 +0200 Subject: [PATCH] Don't fetch Mirror when it's migrating - 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 --- models/task.go | 8 ++++++++ modules/context/repo.go | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/models/task.go b/models/task.go index bade1a639de82..0720d28610168 100644 --- a/models/task.go +++ b/models/task.go @@ -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{ diff --git a/modules/context/repo.go b/modules/context/repo.go index b2c9a21f8e54f..c5e3a69e5c5b6 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -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)