Skip to content

Commit 7b00962

Browse files
lunnylafriks
authored andcommitted
Add SQL execution on log and indexes on table repository and comment (#7740)
* add index on comment * add SQL execution time on log and index owner_id on repository * add migration
1 parent 52feff5 commit 7b00962

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

models/issue_comment.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ const (
9999

100100
// Comment represents a comment in commit and issue page.
101101
type Comment struct {
102-
ID int64 `xorm:"pk autoincr"`
103-
Type CommentType
104-
PosterID int64 `xorm:"INDEX"`
105-
Poster *User `xorm:"-"`
102+
ID int64 `xorm:"pk autoincr"`
103+
Type CommentType `xorm:"index"`
104+
PosterID int64 `xorm:"INDEX"`
105+
Poster *User `xorm:"-"`
106106
OriginalAuthor string
107107
OriginalAuthorID int64
108108
IssueID int64 `xorm:"INDEX"`
@@ -143,7 +143,7 @@ type Comment struct {
143143
ShowTag CommentTag `xorm:"-"`
144144

145145
Review *Review `xorm:"-"`
146-
ReviewID int64
146+
ReviewID int64 `xorm:"index"`
147147
Invalidated bool
148148
}
149149

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ var migrations = []Migration{
236236
NewMigration("add original author/url migration info to issues, comments, and repo ", addOriginalMigrationInfo),
237237
// v90 -> v91
238238
NewMigration("change length of some repository columns", changeSomeColumnsLengthOfRepo),
239+
// v91 -> v92
240+
NewMigration("add index on owner_id of repository and type, review_id of comment", addIndexOnRepositoryAndComment),
239241
}
240242

241243
// Migrate database to current version

models/migrations/v91.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import "github.com/go-xorm/xorm"
8+
9+
func addIndexOnRepositoryAndComment(x *xorm.Engine) error {
10+
type Repository struct {
11+
ID int64 `xorm:"pk autoincr"`
12+
OwnerID int64 `xorm:"index"`
13+
}
14+
15+
if err := x.Sync2(new(Repository)); err != nil {
16+
return err
17+
}
18+
19+
type Comment struct {
20+
ID int64 `xorm:"pk autoincr"`
21+
Type int `xorm:"index"`
22+
ReviewID int64 `xorm:"index"`
23+
}
24+
25+
return x.Sync2(new(Comment))
26+
}

models/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
262262
return fmt.Errorf("Connect to database: %v", err)
263263
}
264264

265+
x.ShowExecTime(true)
265266
x.SetMapper(core.GonicMapper{})
266267
x.SetLogger(NewXORMLogger(!setting.ProdMode))
267268
x.ShowSQL(!setting.ProdMode)
@@ -275,6 +276,7 @@ func SetEngine() (err error) {
275276
return fmt.Errorf("Failed to connect to database: %v", err)
276277
}
277278

279+
x.ShowExecTime(true)
278280
x.SetMapper(core.GonicMapper{})
279281
// WARNING: for serv command, MUST remove the output to os.stdout,
280282
// so use log file to instead print to stdout.

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func NewRepoContext() {
129129
// Repository represents a git repository.
130130
type Repository struct {
131131
ID int64 `xorm:"pk autoincr"`
132-
OwnerID int64 `xorm:"UNIQUE(s)"`
132+
OwnerID int64 `xorm:"UNIQUE(s) index"`
133133
OwnerName string `xorm:"-"`
134134
Owner *User `xorm:"-"`
135135
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`

0 commit comments

Comments
 (0)