From 2817eebdd63a533a09136667458f06fa9533065c Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Tue, 21 Oct 2025 16:40:40 +0200 Subject: [PATCH] fix(perf): add missing index on action_task table (#9789) Fixes #9755, performance regression from #9017. Manually tested by application to a development database and verification that the index is used on `select * from action_task where job_id = 11 and attempt = 1`. I've made the index here cover just the `job_id` field, as the set of values for `attempt` is expected to be very small. Will backport via just the `models/actions/task.go` change (allowing `SyncAllTables` to create it) to avoid a schema migration during the backport (complicated due to the new schema migration module in v14). ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/.md` to be be used for the release notes instead of the title. ## Release notes - Bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/9789): fix(perf): add missing index on action_task table Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9789 Reviewed-by: Michael Kriese Reviewed-by: Gusted Co-authored-by: Mathieu Fenniak Co-committed-by: Mathieu Fenniak (cherry picked from commit ed605a78c844fce47e0c12095e64b1aa0b8bcf3a) --- models/actions/task.go | 2 +- .../v14a_add-action_task-index.go | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 models/forgejo_migrations/v14a_add-action_task-index.go diff --git a/models/actions/task.go b/models/actions/task.go index 6e77db1b18..f272d4d696 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -25,7 +25,7 @@ import ( // ActionTask represents a distribution of job type ActionTask struct { ID int64 - JobID int64 + JobID int64 `xorm:"index"` Job *ActionRunJob `xorm:"-"` Steps []*ActionTaskStep `xorm:"-"` Attempt int64 diff --git a/models/forgejo_migrations/v14a_add-action_task-index.go b/models/forgejo_migrations/v14a_add-action_task-index.go new file mode 100644 index 0000000000..6dd56c3e85 --- /dev/null +++ b/models/forgejo_migrations/v14a_add-action_task-index.go @@ -0,0 +1,23 @@ +// Copyright 2025 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +package forgejo_migrations + +import ( + "xorm.io/xorm" +) + +func init() { + registerMigration(&Migration{ + Description: "add index to action_task.job_id", + Upgrade: addActionTaskJobIDIndex, + }) +} + +func addActionTaskJobIDIndex(x *xorm.Engine) error { + type ActionTask struct { + JobID int64 `xorm:"index"` + } + _, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(ActionTask)) + return err +}