From 5799cd909ad184ab6912f8499b5c9b96419655ca Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 4 May 2022 01:45:42 +0200 Subject: [PATCH 1/2] Only check for non-finished migrating task - Only check if a non-finished migrating task exists for a mirror before fetching the mirror details from the database. - Resolves #19600 - Regression: #19588 --- models/task.go | 12 ++++++------ modules/context/repo.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/task.go b/models/task.go index 0720d28610168..66fb7789e7b19 100644 --- a/models/task.go +++ b/models/task.go @@ -181,12 +181,12 @@ 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, - }) +// HasNonFinishedMigratingTask returns if a non-finished migrating task exist for the repo. +func HasNonFinishedMigratingTask(repoID int64) (bool, error) { + return db.GetEngine(db.DefaultContext). + Where("repo_id=? AND type=? AND status<>?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished). + Table("task"). + Exist() } // GetMigratingTaskByID returns the migrating task by repo's id diff --git a/modules/context/repo.go b/modules/context/repo.go index c5e3a69e5c5b6..3535f4b757ac1 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -373,7 +373,7 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) { // 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) + hasTask, err := models.HasNonFinishedMigratingTask(repo.ID) if err != nil { ctx.ServerError("GetMirrorByRepoID", err) return From ee3dec6124f1b0dc673d7eedb9e22f835cac123f Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 4 May 2022 11:24:22 +0200 Subject: [PATCH 2/2] Clarify function --- models/task.go | 6 +++--- modules/context/repo.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/models/task.go b/models/task.go index 66fb7789e7b19..5528573ca5505 100644 --- a/models/task.go +++ b/models/task.go @@ -181,10 +181,10 @@ func GetMigratingTask(repoID int64) (*Task, error) { return &task, nil } -// HasNonFinishedMigratingTask returns if a non-finished migrating task exist for the repo. -func HasNonFinishedMigratingTask(repoID int64) (bool, error) { +// HasFinishedMigratingTask returns if a finished migration task exists for the repo. +func HasFinishedMigratingTask(repoID int64) (bool, error) { return db.GetEngine(db.DefaultContext). - Where("repo_id=? AND type=? AND status<>?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished). + Where("repo_id=? AND type=? AND status=?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished). Table("task"). Exist() } diff --git a/modules/context/repo.go b/modules/context/repo.go index 3535f4b757ac1..4a1e9aa9e818c 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -371,14 +371,14 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) { if repo.IsMirror { - // 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.HasNonFinishedMigratingTask(repo.ID) + // Check if the mirror has finsihed migrationg, only then we can + // lookup the mirror informtation the database. + finishedMigrating, err := models.HasFinishedMigratingTask(repo.ID) if err != nil { - ctx.ServerError("GetMirrorByRepoID", err) + ctx.ServerError("HasFinishedMigratingTask", err) return } - if !hasTask { + if finishedMigrating { ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID) if err != nil { ctx.ServerError("GetMirrorByRepoID", err)