From 78c98911a3622c59a3427bf675b4537800638403 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Mon, 3 Nov 2025 00:01:51 +0100 Subject: [PATCH] perf: update concurrency group query to be index-capable for status (#9943) When `concurrency.cancel-in-progress: false` is set on a Forgejo Action run, the run will be queued behind other runs of the same concurrency group. This requires a complex query to identify when a run can be dispatched to a runner. During a refactoring of this code in #9927, @earl-warren noted that the query was using a `status NOT IN (...)` clause, which we had discussed in another issue as a possible performance concern -- an index on `status` cannot be used to fulfill that query clause. This PR inverts the clause allowing an index to be used. Covered by existing automated tests in `tests/integration/actions_concurrency_group_queue_test.go` -- a minor commented-out section was removed in these tests while reviewing for this change. ## 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 - [x] I do not want this change to show in the release notes. - Minor implementation change for a feature that is new in the v14 release; not relevant for the release notes. - [ ] 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. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9943 Reviewed-by: Earl Warren Co-authored-by: Mathieu Fenniak Co-committed-by: Mathieu Fenniak --- models/actions/task.go | 4 ++-- tests/integration/actions_concurrency_group_queue_test.go | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/models/actions/task.go b/models/actions/task.go index ad9e1857c8..acf2c11bdd 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -269,8 +269,8 @@ func getConcurrencyCondition() builder.Cond { // // Blocking runs have a running status... builder.Eq{"inner_run.status": StatusRunning}.Or( - // Blocking runs don't have a IsDone status & are younger than the outer_run - builder.NotIn("inner_run.status", DoneStatuses()). + // Blocking runs are pending execution, & are younger than the outer_run + builder.In("inner_run.status", PendingStatuses()). And(builder.Lt{"inner_run.`index`": builder.Expr("outer_run.`index`")}))) // OK to pick if there are no blocking runs diff --git a/tests/integration/actions_concurrency_group_queue_test.go b/tests/integration/actions_concurrency_group_queue_test.go index 72520d43b1..d681ad91ae 100644 --- a/tests/integration/actions_concurrency_group_queue_test.go +++ b/tests/integration/actions_concurrency_group_queue_test.go @@ -53,9 +53,6 @@ func TestActionConcurrencyRunnerFiltering(t *testing.T) { }, } { t.Run(tc.runnerName, func(t *testing.T) { - // defer unittest.OverrideFixtures("tests/integration/fixtures/TestActionConcurrencyRunnerFiltering")() - // require.NoError(t, unittest.PrepareTestDatabase()) - doTest := func() { e := db.GetEngine(t.Context())