forgejo/models
Mathieu Fenniak 28dbbf44cf
Some checks failed
/ release (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-e2e (push) Has been cancelled
testing / test-remote-cacher (redis) (push) Has been cancelled
testing / test-remote-cacher (valkey) (push) Has been cancelled
testing / test-remote-cacher (garnet) (push) Has been cancelled
testing / test-remote-cacher (redict) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled
[v11.0/forgejo] fix: add forgejo doctor cleanup-commit-status command (#10686) (#10783)
**Backport:** #10686

(cherry picked from commit 270317a3ad)

```
NAME:
   forgejo doctor cleanup-commit-status - Cleanup extra records in commit_status table

USAGE:
   forgejo doctor cleanup-commit-status

DESCRIPTION:
   Forgejo suffered from a bug which caused the creation of more entries in the
   "commit_status" table than necessary. This operation removes the redundant
   data caused by the bug. Removing this data is almost always safe.
   These reundant records can be accessed by users through the API, making it
   possible, but unlikely, that removing it could have an impact to
   integrating services (API: /repos/{owner}/{repo}/commits/{ref}/statuses).

   It is safe to run while Forgejo is online.

   On very large Forgejo instances, the performance of operation will improve
   if the buffer-size option is used with large values. Approximately 130 MB of
   memory is required for every 100,000 records in the buffer.

   Bug reference: https://codeberg.org/forgejo/forgejo/issues/10671

OPTIONS:
   --help, -h                       show help
   --custom-path string, -C string  Set custom path (defaults to '{WorkPath}/custom')
   --config string, -c string       Set custom config file (defaults to '{WorkPath}/custom/conf/app.ini')
   --work-path string, -w string    Set Forgejo's working path (defaults to the directory of the Forgejo binary)
   --verbose, -V                    Show process details
   --dry-run                        Report statistics from the operation but do not modify the database
   --buffer-size int                Record count per query while iterating records; larger values are typically faster but use more memory (default: 100000)
   --delete-chunk-size int          Number of records to delete per DELETE query (default: 1000)
```

The cleanup effectively performs `SELECT * FROM commit_status ORDER BY repo_id, sha, context, index, id`, and iterates through the records.  Whenever `index, id` changes without the other fields changing, then it's a useless record that can be deleted.  The major complication is doing that at scale without bringing the entire database table into memory, which is performed through a new iteration method `IterateByKeyset`.

Manually tested against a 455,303 record table in PostgreSQL, MySQL, and SQLite, which was reduced to 10,781 records, dropping 97.5% of the records.

Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10783
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2026-01-13 16:17:06 +01:00
..
actions [v11.0/forgejo] fix(test): TestActionsArtifactOverwrite needs ordered query for pgsql (#8848) 2025-08-10 15:14:06 +02:00
activities [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
admin [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
asymkey fix: use correct GPG key for export 2026-01-06 11:07:10 -07:00
auth fix(sec): consider webauthn for external login 2025-05-02 07:31:20 +02:00
avatars [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
db [v11.0/forgejo] fix: add forgejo doctor cleanup-commit-status command (#10686) (#10783) 2026-01-13 16:17:06 +01:00
dbfs [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
fixtures fix: hide user profile anonymous options on public repo APIs 2026-01-06 10:44:07 -07:00
forgefed [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
forgejo/semver [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
forgejo_migrations [v11.0/forgejo] fix: strict error handling on corrupted DB migration tracking tables (#9775) 2025-10-20 19:13:47 +02:00
git [v11.0/forgejo] fix: add forgejo doctor cleanup-commit-status command (#10686) (#10783) 2026-01-13 16:17:06 +01:00
issues [v11.0/forgejo] fix: do not display the title of unsubscribed issues or pull requests in the notification web page (#9363) 2025-09-19 23:20:03 +02:00
migrations Update golang packages to v1.25 (v11.0/forgejo) (minor) (#9821) 2025-10-23 20:12:49 +02:00
organization [v11.0/forgejo] fix: show membership of limited orgs (#8095) 2025-06-07 01:59:55 +02:00
packages [v11.0/forgejo] chore: merge tests.AddFixtures and unittest.OverrideFixtures (#7649) 2025-04-25 09:59:30 +00:00
perm [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
project [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
pull [v11.0/forgejo] fix: do not ignore automerge while a PR is checking for conflicts (#8456) 2025-07-09 14:09:12 +02:00
quota [v11.0/forgejo] fix: ignore expired artifacts for quota calculation (#7985) 2025-05-28 19:00:00 +02:00
repo [v11.0/forgejo] fix: only redirect to a new owner (organization or user) if the user has permissions to view the new owner (#9089) 2025-08-30 18:52:43 +02:00
secret [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
shared/types [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
system [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
unit [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
unittest [v11.0/forgejo] chore: replace github.com/go-testfixtures/testfixtures (#7729) 2025-04-30 13:21:04 +00:00
user [v11.0/forgejo] fix: allow unactivated users to send recovery mails (#9516) 2025-10-03 09:50:03 +02:00
webhook [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
error.go [v11.0/forgejo] fix: don't allow credentials in migrate/push mirror URL (#9065) 2025-08-30 18:53:14 +02:00
main_test.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
org.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
org_team.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
org_team_test.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
org_test.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
repo.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
repo_test.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
repo_transfer.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
repo_transfer_test.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00