Skip to content

Commit 61a8b48

Browse files
Gustedwxiaoguang
authored andcommitted
Don't fetch Mirror when it's migrating (go-gitea#19588)
- 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 go-gitea#19585 - Regression: go-gitea#19295 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent baf6cc4 commit 61a8b48

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

models/task.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ 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+
})
190+
}
191+
184192
// GetMigratingTaskByID returns the migrating task by repo's id
185193
func GetMigratingTaskByID(id, doerID int64) (*Task, *migration.MigrateOptions, error) {
186194
task := Task{

modules/context/repo.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,24 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
370370
ctx.Data["Permission"] = &ctx.Repo.Permission
371371

372372
if repo.IsMirror {
373-
var err error
374-
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
373+
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)
375377
if err != nil {
376378
ctx.ServerError("GetMirrorByRepoID", err)
377379
return
378380
}
379-
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
380-
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
381-
ctx.Data["Mirror"] = ctx.Repo.Mirror
381+
if !hasTask {
382+
ctx.Repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID)
383+
if err != nil {
384+
ctx.ServerError("GetMirrorByRepoID", err)
385+
return
386+
}
387+
ctx.Data["MirrorEnablePrune"] = ctx.Repo.Mirror.EnablePrune
388+
ctx.Data["MirrorInterval"] = ctx.Repo.Mirror.Interval
389+
ctx.Data["Mirror"] = ctx.Repo.Mirror
390+
}
382391
}
383392

384393
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)

0 commit comments

Comments
 (0)