From 7b009626da2a8a2a46e0e205a3a7ce46cdf7ced2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 5 Aug 2019 22:29:40 +0800 Subject: [PATCH 1/2] 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 --- models/issue_comment.go | 10 +++++----- models/migrations/migrations.go | 2 ++ models/migrations/v91.go | 26 ++++++++++++++++++++++++++ models/models.go | 2 ++ models/repo.go | 2 +- 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 models/migrations/v91.go diff --git a/models/issue_comment.go b/models/issue_comment.go index 5e7ebc0cf3..32bb925e9b 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -99,10 +99,10 @@ const ( // Comment represents a comment in commit and issue page. type Comment struct { - ID int64 `xorm:"pk autoincr"` - Type CommentType - PosterID int64 `xorm:"INDEX"` - Poster *User `xorm:"-"` + ID int64 `xorm:"pk autoincr"` + Type CommentType `xorm:"index"` + PosterID int64 `xorm:"INDEX"` + Poster *User `xorm:"-"` OriginalAuthor string OriginalAuthorID int64 IssueID int64 `xorm:"INDEX"` @@ -143,7 +143,7 @@ type Comment struct { ShowTag CommentTag `xorm:"-"` Review *Review `xorm:"-"` - ReviewID int64 + ReviewID int64 `xorm:"index"` Invalidated bool } diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 5326022b41..6459036e4a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -236,6 +236,8 @@ var migrations = []Migration{ NewMigration("add original author/url migration info to issues, comments, and repo ", addOriginalMigrationInfo), // v90 -> v91 NewMigration("change length of some repository columns", changeSomeColumnsLengthOfRepo), + // v91 -> v92 + NewMigration("add index on owner_id of repository and type, review_id of comment", addIndexOnRepositoryAndComment), } // Migrate database to current version diff --git a/models/migrations/v91.go b/models/migrations/v91.go new file mode 100644 index 0000000000..fea71b5d3b --- /dev/null +++ b/models/migrations/v91.go @@ -0,0 +1,26 @@ +// Copyright 2019 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 "github.com/go-xorm/xorm" + +func addIndexOnRepositoryAndComment(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + OwnerID int64 `xorm:"index"` + } + + if err := x.Sync2(new(Repository)); err != nil { + return err + } + + type Comment struct { + ID int64 `xorm:"pk autoincr"` + Type int `xorm:"index"` + ReviewID int64 `xorm:"index"` + } + + return x.Sync2(new(Comment)) +} diff --git a/models/models.go b/models/models.go index f746f680a5..4c925fa570 100644 --- a/models/models.go +++ b/models/models.go @@ -262,6 +262,7 @@ func NewTestEngine(x *xorm.Engine) (err error) { return fmt.Errorf("Connect to database: %v", err) } + x.ShowExecTime(true) x.SetMapper(core.GonicMapper{}) x.SetLogger(NewXORMLogger(!setting.ProdMode)) x.ShowSQL(!setting.ProdMode) @@ -275,6 +276,7 @@ func SetEngine() (err error) { return fmt.Errorf("Failed to connect to database: %v", err) } + x.ShowExecTime(true) x.SetMapper(core.GonicMapper{}) // WARNING: for serv command, MUST remove the output to os.stdout, // so use log file to instead print to stdout. diff --git a/models/repo.go b/models/repo.go index 20175397af..86370821d3 100644 --- a/models/repo.go +++ b/models/repo.go @@ -129,7 +129,7 @@ func NewRepoContext() { // Repository represents a git repository. type Repository struct { ID int64 `xorm:"pk autoincr"` - OwnerID int64 `xorm:"UNIQUE(s)"` + OwnerID int64 `xorm:"UNIQUE(s) index"` OwnerName string `xorm:"-"` Owner *User `xorm:"-"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` From 1d8915ad5d9889c02dd98ab2c2f29aa8f5ee4dfa Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 5 Aug 2019 17:48:31 +0200 Subject: [PATCH 2/2] Add a lot of extension to language mappings for syntax highlights (#7741) Data partially based on [CodeMirror's meta.js](https://github.com/codemirror/CodeMirror/blob/master/mode/meta.js). Fixes: https://github.com/go-gitea/gitea/issues/6057 --- modules/highlight/highlight.go | 114 +++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 35 deletions(-) diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index 4334480566..ffd88656ae 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -27,49 +27,93 @@ var ( } // Extensions that are same as highlight classes. + // See hljs.listLanguages() for list of language names. highlightExts = map[string]struct{}{ - ".arm": {}, - ".as": {}, - ".sh": {}, - ".cs": {}, - ".cpp": {}, - ".c": {}, - ".css": {}, - ".cmake": {}, - ".bat": {}, - ".dart": {}, - ".patch": {}, - ".erl": {}, - ".go": {}, - ".html": {}, - ".xml": {}, - ".hs": {}, - ".ini": {}, - ".json": {}, - ".java": {}, - ".js": {}, - ".less": {}, - ".lua": {}, - ".php": {}, - ".py": {}, - ".rb": {}, - ".rs": {}, - ".scss": {}, - ".sql": {}, - ".scala": {}, - ".swift": {}, - ".ts": {}, - ".vb": {}, - ".yml": {}, - ".yaml": {}, + ".applescript": {}, + ".arm": {}, + ".as": {}, + ".bash": {}, + ".bat": {}, + ".c": {}, + ".cmake": {}, + ".cpp": {}, + ".cs": {}, + ".css": {}, + ".dart": {}, + ".diff": {}, + ".django": {}, + ".go": {}, + ".gradle": {}, + ".groovy": {}, + ".haml": {}, + ".handlebars": {}, + ".html": {}, + ".ini": {}, + ".java": {}, + ".json": {}, + ".less": {}, + ".lua": {}, + ".php": {}, + ".scala": {}, + ".scss": {}, + ".sql": {}, + ".swift": {}, + ".ts": {}, + ".xml": {}, + ".yaml": {}, } // Extensions that are not same as highlight classes. highlightMapping = map[string]string{ - ".txt": "nohighlight", + ".ahk": "autohotkey", + ".crmsh": "crmsh", + ".dash": "shell", + ".erl": "erlang", ".escript": "erlang", ".ex": "elixir", ".exs": "elixir", + ".f": "fortran", + ".f77": "fortran", + ".f90": "fortran", + ".f95": "fortran", + ".feature": "gherkin", + ".fish": "shell", + ".for": "fortran", + ".hbs": "handlebars", + ".hs": "haskell", + ".hx": "haxe", + ".js": "javascript", + ".jsx": "javascript", + ".ksh": "shell", + ".kt": "kotlin", + ".l": "ocaml", + ".ls": "livescript", + ".md": "markdown", + ".mjs": "javascript", + ".mli": "ocaml", + ".mll": "ocaml", + ".mly": "ocaml", + ".patch": "diff", + ".pl": "perl", + ".pm": "perl", + ".ps1": "powershell", + ".psd1": "powershell", + ".psm1": "powershell", + ".py": "python", + ".pyw": "python", + ".rb": "ruby", + ".rs": "rust", + ".scpt": "applescript", + ".scptd": "applescript", + ".sh": "bash", + ".tcsh": "shell", + ".ts": "typescript", + ".tsx": "typescript", + ".txt": "plaintext", + ".vb": "vbnet", + ".vbs": "vbscript", + ".yml": "yaml", + ".zsh": "shell", } )