Skip to content

Commit 02d17d1

Browse files
committed
improve indices
1 parent 371520d commit 02d17d1

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

models/activities/action.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ 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-
indices := []*schemas.Index{actUserIndex, repoIndex}
102-
if setting.Database.Type.IsPostgreSQL() {
103-
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
104-
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
105-
indices = append(indices, cudIndex)
106-
}
101+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
102+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
103+
104+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex}
107105

108106
return indices
109107
}

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ var migrations = []Migration{
475475
NewMigration("Fix incorrect project type", v1_20.FixIncorrectProjectType),
476476
// v248 -> v249
477477
NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner),
478+
// v249 -> v250
479+
NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices),
478480
}
479481

480482
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v249.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
"xorm.io/xorm/schemas"
9+
)
10+
11+
type Action struct{}
12+
13+
// TableName sets the name of this table
14+
func (a *Action) TableName() string {
15+
return "action"
16+
}
17+
18+
// TableIndices implements xorm's TableIndices interface
19+
func (a *Action) TableIndices() []*schemas.Index {
20+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
21+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
22+
23+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
24+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
25+
26+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
27+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
28+
29+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex}
30+
31+
return indices
32+
}
33+
34+
func ImproveActionTableIndices(x *xorm.Engine) error {
35+
return x.Sync(new(Action))
36+
}

0 commit comments

Comments
 (0)