mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-04 18:24:19 +00:00
e0e18fc286
The API filter `head_sha` on `GET /repos/{owner}/{repo}/actions/runs`
selects runs by `commit_sha`, so `commit_sha` needs an index. For a
action_run table with 212k rows:
- Without the index: the query read 212k rows, and the API request took
35-52 s.
- With the index: the query read 94 rows in 0.14 s, and the API request
took 2-4 s.
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
26 lines
562 B
Go
26 lines
562 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v28
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/modelmigration/base"
|
|
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
// AddActionRunCommitSHAIndex indexes the runs lookup by commit, which the API `head_sha` filter uses.
|
|
func AddActionRunCommitSHAIndex(_ context.Context, x base.EngineMigration) error {
|
|
type ActionRun struct {
|
|
CommitSHA string `xorm:"index"`
|
|
}
|
|
|
|
_, err := x.SyncWithOptions(xorm.SyncOptions{
|
|
IgnoreDropIndices: true,
|
|
IgnoreConstrains: true,
|
|
}, new(ActionRun))
|
|
return err
|
|
}
|