Skip to content

Commit 427ecee

Browse files
committed
Refix indices on actions table
Unforunately the previous PR go-gitea#20035 created indices that were not helpful for SQLite. This PR adjusts these after testing using the try.gitea.io db. Fix go-gitea#20129 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 85d960d commit 427ecee

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

models/action.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func init() {
9292

9393
// TableIndices implements xorm's TableIndices interface
9494
func (a *Action) TableIndices() []*schemas.Index {
95+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
96+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
97+
9598
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
9699
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
97100

98-
repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType)
99-
repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted")
100-
101101
return []*schemas.Index{actUserIndex, repoIndex}
102102
}
103103

models/migrations/migrations.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,11 @@ var migrations = []Migration{
388388
// v215 -> v216
389389
NewMigration("allow to view files in PRs", addReviewViewedFiles),
390390
// v216 -> v217
391-
NewMigration("Improve Action table indices", improveActionTableIndices),
391+
NewMigration("(NOOP) Improve Action table indices", noop216),
392392
// v217 -> v218
393393
NewMigration("Alter hook_task table TEXT fields to LONGTEXT", alterHookTaskTextFieldsToLongText),
394+
// v216 -> v217
395+
NewMigration("Improve Action table indices", improveActionTableIndices),
394396
}
395397

396398
// GetCurrentDBVersion returns the current db version

models/migrations/v216.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,9 @@
55
package migrations
66

77
import (
8-
"code.gitea.io/gitea/modules/timeutil"
9-
108
"xorm.io/xorm"
11-
"xorm.io/xorm/schemas"
129
)
1310

14-
type improveActionTableIndicesAction struct {
15-
ID int64 `xorm:"pk autoincr"`
16-
UserID int64 // Receiver user id.
17-
OpType int
18-
ActUserID int64 // Action user id.
19-
RepoID int64
20-
CommentID int64 `xorm:"INDEX"`
21-
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
22-
RefName string
23-
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
24-
Content string `xorm:"TEXT"`
25-
CreatedUnix timeutil.TimeStamp `xorm:"created"`
26-
}
27-
28-
// TableName sets the name of this table
29-
func (a *improveActionTableIndicesAction) TableName() string {
30-
return "action"
31-
}
32-
33-
// TableIndices implements xorm's TableIndices interface
34-
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
35-
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
36-
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
37-
38-
repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType)
39-
repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted")
40-
41-
return []*schemas.Index{actUserIndex, repoIndex}
42-
}
43-
44-
func improveActionTableIndices(x *xorm.Engine) error {
45-
return x.Sync2(&improveActionTableIndicesAction{})
11+
func noop216(x *xorm.Engine) error {
12+
return nil
4613
}

models/migrations/v218.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"code.gitea.io/gitea/modules/timeutil"
9+
10+
"xorm.io/xorm"
11+
"xorm.io/xorm/schemas"
12+
)
13+
14+
type improveActionTableIndicesAction struct {
15+
ID int64 `xorm:"pk autoincr"`
16+
UserID int64 // Receiver user id.
17+
OpType int
18+
ActUserID int64 // Action user id.
19+
RepoID int64
20+
CommentID int64 `xorm:"INDEX"`
21+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
22+
RefName string
23+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
24+
Content string `xorm:"TEXT"`
25+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
26+
}
27+
28+
// TableName sets the name of this table
29+
func (a *improveActionTableIndicesAction) TableName() string {
30+
return "action"
31+
}
32+
33+
// TableIndices implements xorm's TableIndices interface
34+
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
35+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
36+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
37+
38+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
39+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
40+
41+
return []*schemas.Index{actUserIndex, repoIndex}
42+
}
43+
44+
func improveActionTableIndices(x *xorm.Engine) error {
45+
return x.Sync2(&improveActionTableIndicesAction{})
46+
}

0 commit comments

Comments
 (0)