summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <m.huber@kithara.com>2023-10-21 04:05:29 +0200
committerGitHub <noreply@github.com>2023-10-21 10:05:29 +0800
commitb2f828db5e5878d47de32c292d95c95c4217de68 (patch)
treefd00c29654fb9d4580dc590ba6250c49fc1941ac /modules
parent510d07506e43d1ee1903a676cb0bb305bfbc306f (diff)
downloadgitea-b2f828db5e5878d47de32c292d95c95c4217de68.tar.gz
gitea-b2f828db5e5878d47de32c292d95c95c4217de68.zip
refactor: make db iterate context aware (#27710)
the iteration will run until finished atm. this changes it by checking if if the context got canceled before each run of a loop sequence is executed [View this pull with now whitespace](https://github.com/go-gitea/gitea/pull/27710/files?diff=unified&w=1)
Diffstat (limited to 'modules')
-rw-r--r--modules/doctor/repository.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/modules/doctor/repository.go b/modules/doctor/repository.go
index aa3f064ddd..d69ba2048b 100644
--- a/modules/doctor/repository.go
+++ b/modules/doctor/repository.go
@@ -37,24 +37,29 @@ func deleteOrphanedRepos(ctx context.Context) (int64, error) {
adminUser := &user_model.User{IsAdmin: true}
for {
- var ids []int64
- if err := e.Table("`repository`").
- Join("LEFT", "`user`", "repository.owner_id=user.id").
- Where(builder.IsNull{"`user`.id"}).
- Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
- return deleted, err
- }
+ select {
+ case <-ctx.Done():
+ return deleted, ctx.Err()
+ default:
+ var ids []int64
+ if err := e.Table("`repository`").
+ Join("LEFT", "`user`", "repository.owner_id=user.id").
+ Where(builder.IsNull{"`user`.id"}).
+ Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
+ return deleted, err
+ }
- // if we don't get ids we have deleted them all
- if len(ids) == 0 {
- return deleted, nil
- }
+ // if we don't get ids we have deleted them all
+ if len(ids) == 0 {
+ return deleted, nil
+ }
- for _, id := range ids {
- if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
- return deleted, err
+ for _, id := range ids {
+ if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
+ return deleted, err
+ }
+ deleted++
}
- deleted++
}
}
}