loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve indices for `action` table (#23532)

Close #21611

Add the index mentioned in
https://github.com/go-gitea/gitea/issues/21611#issuecomment-1451113252 .
Since we already have an index for `("created_unix", "user_id",
"is_deleted")` columns on PostgreSQL, I removed the database type check
to apply this index to all types of databases.

authored by

Zettat123 and committed by
GitHub
b958dba1 e52ea44e

+51 -6
+4 -6
models/activities/action.go
··· 98 98 actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) 99 99 actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") 100 100 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} 107 105 108 106 return indices 109 107 }
+2
models/migrations/migrations.go
··· 475 475 NewMigration("Fix incorrect project type", v1_20.FixIncorrectProjectType), 476 476 // v248 -> v249 477 477 NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner), 478 + // v249 -> v250 479 + NewMigration("Improve Action table indices v3", v1_20.ImproveActionTableIndices), 478 480 } 479 481 480 482 // GetCurrentDBVersion returns the current db version
+45
models/migrations/v1_20/v249.go
··· 1 + // Copyright 2023 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package v1_20 //nolint 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/timeutil" 8 + 9 + "xorm.io/xorm" 10 + "xorm.io/xorm/schemas" 11 + ) 12 + 13 + type Action struct { 14 + UserID int64 // Receiver user id. 15 + ActUserID int64 // Action user id. 16 + RepoID int64 17 + IsDeleted bool `xorm:"NOT NULL DEFAULT false"` 18 + IsPrivate bool `xorm:"NOT NULL DEFAULT false"` 19 + CreatedUnix timeutil.TimeStamp `xorm:"created"` 20 + } 21 + 22 + // TableName sets the name of this table 23 + func (a *Action) TableName() string { 24 + return "action" 25 + } 26 + 27 + // TableIndices implements xorm's TableIndices interface 28 + func (a *Action) TableIndices() []*schemas.Index { 29 + repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType) 30 + repoIndex.AddColumn("repo_id", "user_id", "is_deleted") 31 + 32 + actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) 33 + actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") 34 + 35 + cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType) 36 + cudIndex.AddColumn("created_unix", "user_id", "is_deleted") 37 + 38 + indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex} 39 + 40 + return indices 41 + } 42 + 43 + func ImproveActionTableIndices(x *xorm.Engine) error { 44 + return x.Sync(new(Action)) 45 + }