-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Improve action table indices #19472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve action table indices #19472
Changes from all commits
133c63e
2f2234e
aca1e3b
4a2c406
e2b1102
9d186bd
64bc7cd
a1f182b
715e529
24d7b94
de86bd4
65ed667
1ad852c
a0147f0
4b32d19
cf876d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
zeripath marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"xorm.io/xorm/schemas" | ||
) | ||
|
||
type improveActionTableIndicesAction struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know whether a private struct could work with xorm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if you're meaning this as a comment, e.g. I didn't know that a private struct would work with xorm, or if you're trying to express doubt that this will work, e.g. I don't think a private struct will work with xorm. It will work. If you are given a pointer to a nonExportedStruct: package someplace
type notExportedStruct {
Exported string
}
func NewNotExported() *notExportedStruct {
return ¬ExportedStruct{}
} you can always create another copy of it using: package main
import "someplace"
func main() {
notExported := somplace.NewNotExported()
val := reflect.ValueOf(notExported).Elem()
typ := val.Type()
newNotExportedVal := reflect.New(typ)
newNotExportedVal.Elem().FieldByName("Exported").SetString("I have been set by reflection")
fmt.Println(newNotExportedVal.Interface())
} Which is what xorm does internally anyway. Xorm doesn't need to know or be able to cast to the non-exported type - it just uses reflection to look across the exported fields which will always work or casts to interfaces it knows e.g. TableName. |
||
ID int64 `xorm:"pk autoincr"` | ||
UserID int64 // Receiver user id. | ||
OpType int | ||
ActUserID int64 // Action user id. | ||
RepoID int64 | ||
CommentID int64 `xorm:"INDEX"` | ||
IsDeleted bool `xorm:"NOT NULL DEFAULT false"` | ||
RefName string | ||
IsPrivate bool `xorm:"NOT NULL DEFAULT false"` | ||
Content string `xorm:"TEXT"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||
} | ||
|
||
// TableName sets the name of this table | ||
func (a *improveActionTableIndicesAction) TableName() string { | ||
return "action" | ||
} | ||
|
||
// TableIndices implements xorm's TableIndices interface | ||
func (a *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") | ||
|
||
repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType) | ||
repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted") | ||
|
||
return []*schemas.Index{actUserIndex, repoIndex} | ||
} | ||
|
||
func improveActionTableIndices(x *xorm.Engine) error { | ||
{ | ||
type Action struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
UserID int64 `xorm:"INDEX"` // Receiver user id. | ||
OpType int | ||
ActUserID int64 `xorm:"INDEX"` // Action user id. | ||
RepoID int64 `xorm:"INDEX"` | ||
CommentID int64 `xorm:"INDEX"` | ||
IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"` | ||
RefName string | ||
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` | ||
Content string `xorm:"TEXT"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
} | ||
if err := x.Sync2(&Action{}); err != nil { | ||
return err | ||
} | ||
if err := x.DropIndexes(&Action{}); err != nil { | ||
return err | ||
} | ||
} | ||
return x.Sync2(&improveActionTableIndicesAction{}) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.