Procházet zdrojové kódy

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
tags/v1.18.0-dev
Gusted před 2 roky
rodič
revize
3114cd30b8
Žádný účet není propojen s e-mailovou adresou tvůrce revize
2 změnil soubory, kde provedl 11 přidání a 11 odebrání
  1. 6
    6
      models/task.go
  2. 5
    5
      modules/context/repo.go

+ 6
- 6
models/task.go Zobrazit soubor

@@ -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,
})
// 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).
Table("task").
Exist()
}

// GetMigratingTaskByID returns the migrating task by repo's id

+ 5
- 5
modules/context/repo.go Zobrazit soubor

@@ -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.HasMigratingTask(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)

Načítá se…
Zrušit
Uložit