Skip to content

Commit

Permalink
Add combined index for issue_user.uid and issue_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-sauer authored and lunny committed Dec 14, 2023
1 parent cbf923e commit b97acab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions models/issues/issue_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
// IssueUser represents an issue-user relation.
type IssueUser struct {
ID int64 `xorm:"pk autoincr"`
UID int64 `xorm:"INDEX"` // User ID.
IssueID int64 `xorm:"INDEX"`
UID int64 `xorm:"INDEX INDEX(uidtoissue)"` // User ID.
IssueID int64 `xorm:"INDEX INDEX(uidtoissue)"`
IsRead bool
IsMentioned bool
}
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ var migrations = []Migration{
NewMigration("Add auth_token table", v1_22.CreateAuthTokenTable),
// v282 -> v283
NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID),
// v283 -> v284
NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser),
}

// GetCurrentDBVersion returns the current db version
Expand Down
17 changes: 17 additions & 0 deletions models/migrations/v1_22/v283.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_22 //nolint

import (
"xorm.io/xorm"
)

func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
type IssueUser struct {
UID int64 `xorm:"INDEX(uidtoissue)"` // User ID.
IssueID int64 `xorm:"INDEX(uidtoissue)"`
}

return x.Sync(&IssueUser{})
}

0 comments on commit b97acab

Please sign in to comment.