Skip to content

Commit bb1d8fc

Browse files
committed
In PushMirrorsIterate and MirrorsIterate if limit is negative do not set it
The documentation allows the mirror update queue to add all potential mirrors to the queue by setting the limits negative. Unfortunately a change to the iterator code has missed this subtly and resulted in passing negative numbers to the LIMIT SQL statement. This causes bugs on some DB systems. Fix go-gitea#20667 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 208b4ee commit bb1d8fc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

models/repo/mirror.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ func DeleteMirrorByRepoID(repoID int64) error {
108108

109109
// MirrorsIterate iterates all mirror repositories.
110110
func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
111-
return db.GetEngine(db.DefaultContext).
111+
sess := db.GetEngine(db.DefaultContext).
112112
Where("next_update_unix<=?", time.Now().Unix()).
113113
And("next_update_unix!=0").
114-
OrderBy("updated_unix ASC").
115-
Limit(limit).
116-
Iterate(new(Mirror), f)
114+
OrderBy("updated_unix ASC")
115+
if limit > 0 {
116+
sess = sess.Limit(limit)
117+
}
118+
return sess.Iterate(new(Mirror), f)
117119
}
118120

119121
// InsertMirror inserts a mirror to database

models/repo/pushmirror.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ func GetPushMirrorsSyncedOnCommit(repoID int64) ([]*PushMirror, error) {
129129

130130
// PushMirrorsIterate iterates all push-mirror repositories.
131131
func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean interface{}) error) error {
132-
return db.GetEngine(ctx).
132+
sess := db.GetEngine(ctx).
133133
Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
134134
And("`interval` != 0").
135-
OrderBy("last_update ASC").
136-
Limit(limit).
137-
Iterate(new(PushMirror), f)
135+
OrderBy("last_update ASC")
136+
if limit > 0 {
137+
sess = sess.Limit(limit)
138+
}
139+
return sess.Iterate(new(PushMirror), f)
138140
}

0 commit comments

Comments
 (0)