0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-23 15:53:07 -05:00

Only check for non-finished migrating task (#19601)

* 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

* Clarify function
This commit is contained in:
Gusted 2022-05-04 10:09:42 +00:00 committed by GitHub
parent 9c04da37d0
commit 3114cd30b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -181,12 +181,12 @@ func GetMigratingTask(repoID int64) (*Task, error) {
return &task, nil return &task, nil
} }
// HasMigratingTask returns if migrating task exist for repo. // HasFinishedMigratingTask returns if a finished migration task exists for the repo.
func HasMigratingTask(repoID int64) (bool, error) { func HasFinishedMigratingTask(repoID int64) (bool, error) {
return db.GetEngine(db.DefaultContext).Exist(&Task{ return db.GetEngine(db.DefaultContext).
RepoID: repoID, Where("repo_id=? AND type=? AND status=?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished).
Type: structs.TaskTypeMigrateRepo, Table("task").
}) Exist()
} }
// GetMigratingTaskByID returns the migrating task by repo's id // GetMigratingTaskByID returns the migrating task by repo's id

View file

@ -371,14 +371,14 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
if repo.IsMirror { if repo.IsMirror {
// Check if there's a migrating task. // Check if the mirror has finsihed migrationg, only then we can
// If it does exist, don't fetch the Mirror from the database as it doesn't exist yet. // lookup the mirror informtation the database.
hasTask, err := models.HasMigratingTask(repo.ID) finishedMigrating, err := models.HasFinishedMigratingTask(repo.ID)
if err != nil { if err != nil {
ctx.ServerError("GetMirrorByRepoID", err) ctx.ServerError("HasFinishedMigratingTask", err)
return return
} }
if !hasTask { if finishedMigrating {
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)