Skip to content

Commit 3114cd3

Browse files
author
Gusted
authored
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
1 parent 9c04da3 commit 3114cd3

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

models/task.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ func GetMigratingTask(repoID int64) (*Task, error) {
181181
return &task, nil
182182
}
183183

184-
// HasMigratingTask returns if migrating task exist for repo.
185-
func HasMigratingTask(repoID int64) (bool, error) {
186-
return db.GetEngine(db.DefaultContext).Exist(&Task{
187-
RepoID: repoID,
188-
Type: structs.TaskTypeMigrateRepo,
189-
})
184+
// HasFinishedMigratingTask returns if a finished migration task exists for the repo.
185+
func HasFinishedMigratingTask(repoID int64) (bool, error) {
186+
return db.GetEngine(db.DefaultContext).
187+
Where("repo_id=? AND type=? AND status=?", repoID, structs.TaskTypeMigrateRepo, structs.TaskStatusFinished).
188+
Table("task").
189+
Exist()
190190
}
191191

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

modules/context/repo.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
371371

372372
if repo.IsMirror {
373373

374-
// Check if there's a migrating task.
375-
// If it does exist, don't fetch the Mirror from the database as it doesn't exist yet.
376-
hasTask, err := models.HasMigratingTask(repo.ID)
374+
// Check if the mirror has finsihed migrationg, only then we can
375+
// lookup the mirror informtation the database.
376+
finishedMigrating, err := models.HasFinishedMigratingTask(repo.ID)
377377
if err != nil {
378-
ctx.ServerError("GetMirrorByRepoID", err)
378+
ctx.ServerError("HasFinishedMigratingTask", err)
379379
return
380380
}
381-
if !hasTask {
381+
if finishedMigrating {
382382
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
383383
if err != nil {
384384
ctx.ServerError("GetMirrorByRepoID", err)

0 commit comments

Comments
 (0)