Skip to content

Commit 8fc80b3

Browse files
authored
Add another index for Action table on postgres (go-gitea#21033) (go-gitea#21054)
Backport go-gitea#21033 In go-gitea#21031 we have discovered that on very big tables postgres will use a search involving the sort term in preference to the restrictive index. Therefore we add another index for postgres and update the original migration. Fix go-gitea#21031 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 71aa64a commit 8fc80b3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

models/action.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ func (a *Action) TableIndices() []*schemas.Index {
9898
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
9999
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
100100

101-
return []*schemas.Index{actUserIndex, repoIndex}
101+
indices := []*schemas.Index{actUserIndex, repoIndex}
102+
if setting.Database.UsePostgreSQL {
103+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
104+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
105+
indices = append(indices, cudIndex)
106+
}
107+
108+
return indices
102109
}
103110

104111
// GetOpType gets the ActionType of this action.

models/migrations/v218.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package migrations
66

77
import (
8+
"code.gitea.io/gitea/modules/setting"
89
"code.gitea.io/gitea/modules/timeutil"
910

1011
"xorm.io/xorm"
@@ -37,8 +38,14 @@ func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index {
3738

3839
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
3940
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
40-
41-
return []*schemas.Index{actUserIndex, repoIndex}
41+
indices := []*schemas.Index{actUserIndex, repoIndex}
42+
if setting.Database.UsePostgreSQL {
43+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
44+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
45+
indices = append(indices, cudIndex)
46+
}
47+
48+
return indices
4249
}
4350

4451
func improveActionTableIndices(x *xorm.Engine) error {

0 commit comments

Comments
 (0)