Skip to content

Commit

Permalink
In PushMirrorsIterate and MirrorsIterate if limit is negative do not …
Browse files Browse the repository at this point in the history
…set it (go-gitea#20837)

Backport go-gitea#20837
  • Loading branch information
zeripath committed Aug 21, 2022
1 parent 9e8b1c6 commit ea3935e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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 @@ -95,10 +95,12 @@ func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) {

// PushMirrorsIterate iterates all push-mirror repositories.
func PushMirrorsIterate(limit int, f func(idx int, bean interface{}) error) error {
return db.GetEngine(db.DefaultContext).
sess := db.GetEngine(db.DefaultContext).
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)
}

0 comments on commit ea3935e

Please sign in to comment.