forgejo/models
forgejo-backport-action 714b88f8b2 [v13.0/forgejo] fix: db.Iterate can miss records, can return records twice (#9723)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/9657

Fixes #9644.

Rewrites `db.Iterate` so that it performs DB queries in this format:
- First: `SELECT ...columns... FROM table ORDER BY id LIMIT ...buffer-size...`
- Subsequent buffer fills: adding a `WHERE id > ...last-id-from-previous...`

This approach:
- Prevents records from being missed or returned twice
- Returns records in a predictable order
- Should be faster, by virtue of using database indexes on the primary key to perform the query
- Doesn't rely on any unpredictable database behaviour when using `LIMIT` and `OFFSET` without an `ORDER BY`
- (Downside: does require reflection to read field values off Go structures for the primary key value)

Expands the automated tests to include the predicted failure case identified in #9644, which verified the previous broken behaviour, as well as verifying that the `cond` parameter is applied which was previously not covered by test automation.

Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9723
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
2025-10-17 06:45:24 +02:00
..
actions save pre-execution errors to the DB when workflow execution is prevented by user data 2025-10-05 21:21:30 -06:00
activities
admin
asymkey
auth chore: add SQL fault injector testing (#9314) 2025-09-18 00:39:06 +02:00
avatars
db [v13.0/forgejo] fix: db.Iterate can miss records, can return records twice (#9723) 2025-10-17 06:45:24 +02:00
dbfs
fixtures fix: loading action logs on a task that isn't fetched yet, fails when the job is fetched (#9293) 2025-09-14 14:30:02 +02:00
forgefed
forgejo/semver Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
forgejo_migrations save pre-execution errors to the DB when workflow execution is prevented by user data 2025-10-05 21:21:30 -06:00
git
issues fix: do not display the title of unsubscribed issues or pull requests in the notification web page (#9362) 2025-09-19 22:32:06 +02:00
migrations chore: replace xorm v1.3.9 with v1.3.9-forgejo.1, preparation for foreign key additions (#9326) 2025-09-19 06:30:04 +02:00
moderation
organization
packages
perm
project
pull
quota fix: quotas double counting repo size when calculating size:all (#9234) 2025-09-11 16:30:04 +02:00
repo chore: remove redundant code (#9378) 2025-09-22 09:18:19 +02:00
secret
shared/types
system
unit
unittest chore: add SQL fault injector testing (#9314) 2025-09-18 00:39:06 +02:00
user [v13.0/forgejo] fix: allow unactivated users to send recovery mails (#9515) 2025-10-03 08:16:44 +02:00
webhook
error.go
main_test.go
org.go
org_team.go
org_team_test.go
org_test.go
repo.go
repo_test.go
repo_transfer.go
repo_transfer_test.go