Skip to content

Commit 9a74d1d

Browse files
committed
Use IndexHint for mysql on action to improvement performance
1 parent 92390da commit 9a74d1d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ require (
121121
mvdan.cc/xurls/v2 v2.5.0
122122
strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251
123123
xorm.io/builder v0.3.13
124-
xorm.io/xorm v1.3.5
124+
xorm.io/xorm v1.3.5-0.20231219045404-7ae7474bcbf6
125125
)
126126

127127
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,5 +1510,5 @@ strk.kbt.io/projects/go/libravatar v0.0.0-20191008002943-06d1c002b251/go.mod h1:
15101510
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
15111511
xorm.io/builder v0.3.13 h1:a3jmiVVL19psGeXx8GIurTp7p0IIgqeDmwhcR6BAOAo=
15121512
xorm.io/builder v0.3.13/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE=
1513-
xorm.io/xorm v1.3.5 h1:cMdszQP8meXLpa7hI4kv9t6AozGNDxqG2qujinGpdsg=
1514-
xorm.io/xorm v1.3.5/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
1513+
xorm.io/xorm v1.3.5-0.20231219045404-7ae7474bcbf6 h1:1pmm7oRgfzL3HKwCaXaUC6tItJGSlrWXZqh28lFd9K0=
1514+
xorm.io/xorm v1.3.5-0.20231219045404-7ae7474bcbf6/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=

models/activities/action.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,12 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
446446
return nil, 0, err
447447
}
448448

449-
sess := db.GetEngine(ctx).Where(cond).
450-
Select("`action`.*"). // this line will avoid select other joined table's columns
451-
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
449+
sess := db.GetEngine(ctx).Where(cond)
450+
if setting.Database.Type.IsMySQL() {
451+
sess = sess.IndexHint("USE", "JOIN", "IDX_action_c_u_d")
452+
}
453+
sess = sess.Select("`action`.*"). // this line will avoid select other joined table's columns
454+
Join("INNER", "repository", "`repository`.id = `action`.repo_id")
452455

453456
opts.SetDefaultValues()
454457
sess = db.SetSessionPagination(sess, &opts)

0 commit comments

Comments
 (0)