@@ -18,6 +18,7 @@ import (
18
18
"code.gitea.io/gitea/modules/timeutil"
19
19
20
20
"xorm.io/builder"
21
+ "xorm.io/xorm/schemas"
21
22
)
22
23
23
24
type (
@@ -50,25 +51,64 @@ const (
50
51
// Notification represents a notification
51
52
type Notification struct {
52
53
ID int64 `xorm:"pk autoincr"`
53
- UserID int64 `xorm:"INDEX NOT NULL"`
54
- RepoID int64 `xorm:"INDEX NOT NULL"`
54
+ UserID int64 `xorm:"NOT NULL"`
55
+ RepoID int64 `xorm:"NOT NULL"`
55
56
56
- Status NotificationStatus `xorm:"SMALLINT INDEX NOT NULL"`
57
- Source NotificationSource `xorm:"SMALLINT INDEX NOT NULL"`
57
+ Status NotificationStatus `xorm:"SMALLINT NOT NULL"`
58
+ Source NotificationSource `xorm:"SMALLINT NOT NULL"`
58
59
59
- IssueID int64 `xorm:"INDEX NOT NULL"`
60
- CommitID string `xorm:"INDEX"`
60
+ IssueID int64 `xorm:"NOT NULL"`
61
+ CommitID string
61
62
CommentID int64
62
63
63
- UpdatedBy int64 `xorm:"INDEX NOT NULL"`
64
+ UpdatedBy int64 `xorm:"NOT NULL"`
64
65
65
66
Issue * issues_model.Issue `xorm:"-"`
66
67
Repository * repo_model.Repository `xorm:"-"`
67
68
Comment * issues_model.Comment `xorm:"-"`
68
69
User * user_model.User `xorm:"-"`
69
70
70
- CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
71
- UpdatedUnix timeutil.TimeStamp `xorm:"updated INDEX NOT NULL"`
71
+ CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
72
+ UpdatedUnix timeutil.TimeStamp `xorm:"updated NOT NULL"`
73
+ }
74
+
75
+ // TableIndices implements xorm's TableIndices interface
76
+ func (n * Notification ) TableIndices () []* schemas.Index {
77
+ indices := make ([]* schemas.Index , 0 , 8 )
78
+ usuuIndex := schemas .NewIndex ("u_s_uu" , schemas .IndexType )
79
+ usuuIndex .AddColumn ("user_id" , "status" , "updated_unix" )
80
+ indices = append (indices , usuuIndex )
81
+
82
+ // Add the individual indices that were previously defined in struct tags
83
+ userIDIndex := schemas .NewIndex ("idx_notification_user_id" , schemas .IndexType )
84
+ userIDIndex .AddColumn ("user_id" )
85
+ indices = append (indices , userIDIndex )
86
+
87
+ repoIDIndex := schemas .NewIndex ("idx_notification_repo_id" , schemas .IndexType )
88
+ repoIDIndex .AddColumn ("repo_id" )
89
+ indices = append (indices , repoIDIndex )
90
+
91
+ statusIndex := schemas .NewIndex ("idx_notification_status" , schemas .IndexType )
92
+ statusIndex .AddColumn ("status" )
93
+ indices = append (indices , statusIndex )
94
+
95
+ sourceIndex := schemas .NewIndex ("idx_notification_source" , schemas .IndexType )
96
+ sourceIndex .AddColumn ("source" )
97
+ indices = append (indices , sourceIndex )
98
+
99
+ issueIDIndex := schemas .NewIndex ("idx_notification_issue_id" , schemas .IndexType )
100
+ issueIDIndex .AddColumn ("issue_id" )
101
+ indices = append (indices , issueIDIndex )
102
+
103
+ commitIDIndex := schemas .NewIndex ("idx_notification_commit_id" , schemas .IndexType )
104
+ commitIDIndex .AddColumn ("commit_id" )
105
+ indices = append (indices , commitIDIndex )
106
+
107
+ updatedByIndex := schemas .NewIndex ("idx_notification_updated_by" , schemas .IndexType )
108
+ updatedByIndex .AddColumn ("updated_by" )
109
+ indices = append (indices , updatedByIndex )
110
+
111
+ return indices
72
112
}
73
113
74
114
func init () {
0 commit comments