aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-03-01 03:41:06 +0800
committerGitHub <noreply@github.com>2022-02-28 20:41:06 +0100
commitb75ad7b87f122a1386cb0e576ce83cc000f6d010 (patch)
tree14835b769ae37a82e463e38b03f49d0bea515b69 /services
parent59959ab222cee6e679aa373b37c6c4bce348e825 (diff)
downloadgitea-b75ad7b87f122a1386cb0e576ce83cc000f6d010.tar.gz
gitea-b75ad7b87f122a1386cb0e576ce83cc000f6d010.zip
Improve mirror iterator (#18928)
* Improve mirror iterator * fix test
Diffstat (limited to 'services')
-rw-r--r--services/mirror/mirror.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/services/mirror/mirror.go b/services/mirror/mirror.go
index 5639a08f96..ed3a878d01 100644
--- a/services/mirror/mirror.go
+++ b/services/mirror/mirror.go
@@ -55,9 +55,7 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
}
log.Trace("Doing: Update")
- requested := 0
-
- handler := func(idx int, bean interface{}, limit int) error {
+ handler := func(idx int, bean interface{}) error {
var item SyncRequest
var repo *repo_model.Repository
if m, ok := bean.(*repo_model.Mirror); ok {
@@ -104,35 +102,35 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
}
return err
}
-
- requested++
- if limit > 0 && requested > limit {
- return errLimit
- }
return nil
}
pullMirrorsRequested := 0
if pullLimit != 0 {
- requested = 0
- if err := repo_model.MirrorsIterate(func(idx int, bean interface{}) error {
- return handler(idx, bean, pullLimit)
+ if err := repo_model.MirrorsIterate(pullLimit, func(idx int, bean interface{}) error {
+ if err := handler(idx, bean); err != nil {
+ return err
+ }
+ pullMirrorsRequested++
+ return nil
}); err != nil && err != errLimit {
log.Error("MirrorsIterate: %v", err)
return err
}
- pullMirrorsRequested, requested = requested, 0
}
+
pushMirrorsRequested := 0
if pushLimit != 0 {
- requested = 0
- if err := repo_model.PushMirrorsIterate(func(idx int, bean interface{}) error {
- return handler(idx, bean, pushLimit)
+ if err := repo_model.PushMirrorsIterate(pushLimit, func(idx int, bean interface{}) error {
+ if err := handler(idx, bean); err != nil {
+ return err
+ }
+ pushMirrorsRequested++
+ return nil
}); err != nil && err != errLimit {
log.Error("PushMirrorsIterate: %v", err)
return err
}
- pushMirrorsRequested, requested = requested, 0
}
log.Trace("Finished: Update: %d pull mirrors and %d push mirrors queued", pullMirrorsRequested, pushMirrorsRequested)
return nil