From debd74e1b688f02293848db89948f5be6b12740a Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 23 Jun 2025 08:00:18 +0200 Subject: [PATCH] fix: add an index to the ActionRun.stopped column (#8252) The models/actions/run.go:GetRunBefore function sorts ActionRun rows to get the most recently stopped. Since the ActionRun rows do not expire, the cost will keep increasing over time. The index is meant to ensure the execution time of the associated query does not grow linearly with the number of rows in the ActionRun table. Ref https://codeberg.org/forgejo/forgejo/pulls/7491/files#issuecomment-5495441 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8252 Reviewed-by: Christopher Besch Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- models/forgejo_migrations/migrate.go | 2 ++ models/forgejo_migrations/v35.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 models/forgejo_migrations/v35.go diff --git a/models/forgejo_migrations/migrate.go b/models/forgejo_migrations/migrate.go index 6a6922ec4e..737350b019 100644 --- a/models/forgejo_migrations/migrate.go +++ b/models/forgejo_migrations/migrate.go @@ -107,6 +107,8 @@ var migrations = []*Migration{ NewMigration("Add federated user activity tables, update the `federated_user` table & add indexes", FederatedUserActivityMigration), // v33 -> v34 NewMigration("Add `notify-email` column to `action_run` table", AddNotifyEmailToActionRun), + // v34 -> v35 + NewMigration("Add index to `stopped` column in `action_run` table", AddIndexToActionRunStopped), } // GetCurrentDBVersion returns the current Forgejo database version. diff --git a/models/forgejo_migrations/v35.go b/models/forgejo_migrations/v35.go new file mode 100644 index 0000000000..0fb3b43e2c --- /dev/null +++ b/models/forgejo_migrations/v35.go @@ -0,0 +1,19 @@ +// Copyright 2025 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +package forgejo_migrations //nolint:revive + +import ( + "forgejo.org/modules/timeutil" + + "xorm.io/xorm" +) + +func AddIndexToActionRunStopped(x *xorm.Engine) error { + type ActionRun struct { + ID int64 + Stopped timeutil.TimeStamp `xorm:"index"` + } + + return x.Sync(&ActionRun{}) +}