Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In PushMirrorsIterate and MirrorsIterate if limit is negative do not … #20837

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 #20667

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Aug 17, 2022
commit bb1d8fc51c5f21c16bc39346d053da230e0293b1
10 changes: 6 additions & 4 deletions models/repo/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ func DeleteMirrorByRepoID(repoID int64) error {

// MirrorsIterate iterates all mirror repositories.
func MirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
return db.GetEngine(db.DefaultContext).
sess := db.GetEngine(db.DefaultContext).
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
OrderBy("updated_unix ASC").
Limit(limit).
Iterate(new(Mirror), f)
OrderBy("updated_unix ASC")
if limit > 0 {
sess = sess.Limit(limit)
}
return sess.Iterate(new(Mirror), f)
}

// InsertMirror inserts a mirror to database
Expand Down
10 changes: 6 additions & 4 deletions models/repo/pushmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ func GetPushMirrorsSyncedOnCommit(repoID int64) ([]*PushMirror, error) {

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