diff options
author | zeripath <art27@cantab.net> | 2022-09-03 17:27:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-03 17:27:59 +0100 |
commit | 58a80ba69c73715dfc527ec1ee327f7c6ad4c1d6 (patch) | |
tree | a023551f401ba544e77b6964926b69a9cf753750 /models | |
parent | 5bc73ca666588ac26cc7cea219866b79c5263527 (diff) | |
download | gitea-58a80ba69c73715dfc527ec1ee327f7c6ad4c1d6.tar.gz gitea-58a80ba69c73715dfc527ec1ee327f7c6ad4c1d6.zip |
Add another index for Action table on postgres (#21033)
In #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 #21031
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models')
-rw-r--r-- | models/activities/action.go | 9 | ||||
-rw-r--r-- | models/migrations/v218.go | 11 |
2 files changed, 17 insertions, 3 deletions
diff --git a/models/activities/action.go b/models/activities/action.go index 78a519e9a7..22419e20db 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -98,7 +98,14 @@ func (a *Action) TableIndices() []*schemas.Index { actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") - return []*schemas.Index{actUserIndex, repoIndex} + indices := []*schemas.Index{actUserIndex, repoIndex} + if setting.Database.UsePostgreSQL { + cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType) + cudIndex.AddColumn("created_unix", "user_id", "is_deleted") + indices = append(indices, cudIndex) + } + + return indices } // GetOpType gets the ActionType of this action. diff --git a/models/migrations/v218.go b/models/migrations/v218.go index dee8e5517e..e08c6c5b0f 100644 --- a/models/migrations/v218.go +++ b/models/migrations/v218.go @@ -5,6 +5,7 @@ package migrations import ( + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "xorm.io/xorm" @@ -37,8 +38,14 @@ func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index { actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") - - return []*schemas.Index{actUserIndex, repoIndex} + indices := []*schemas.Index{actUserIndex, repoIndex} + if setting.Database.UsePostgreSQL { + cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType) + cudIndex.AddColumn("created_unix", "user_id", "is_deleted") + indices = append(indices, cudIndex) + } + + return indices } func improveActionTableIndices(x *xorm.Engine) error { |