diff options
author | Thomas Boerger <thomas@webhippie.de> | 2016-03-27 22:54:31 +0200 |
---|---|---|
committer | Thomas Boerger <thomas@webhippie.de> | 2016-03-27 22:59:57 +0200 |
commit | 79a1bfd9632c40ce3ee15c2dcbb8f322d871ade0 (patch) | |
tree | 307de82e55a6917ee586b5a93fc9123a4b500970 /models | |
parent | ac53bb593d12bac3b44380defe73d13e728cd142 (diff) | |
download | gitea-79a1bfd9632c40ce3ee15c2dcbb8f322d871ade0.tar.gz gitea-79a1bfd9632c40ce3ee15c2dcbb8f322d871ade0.zip |
Try to make the SQL queries cleaner and more secure
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/models/issue.go b/models/issue.go index edc46689d9..5727e07b11 100644 --- a/models/issue.go +++ b/models/issue.go @@ -5,7 +5,6 @@ package models import ( - "bytes" "errors" "fmt" "io" @@ -513,7 +512,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { if len(opts.RepoIDs) == 0 { return make([]*Issue, 0), nil } - sess.Where("issue.repo_id IN ("+strings.Join(base.Int64sToStrings(opts.RepoIDs), ",")+")").And("issue.is_closed=?", opts.IsClosed) + sess.In("issue.repo_id", base.Int64sToStrings(opts.RepoIDs)).And("issue.is_closed=?", opts.IsClosed) } else { sess.Where("issue.is_closed=?", opts.IsClosed) } @@ -684,18 +683,8 @@ func GetIssueUserPairsByRepoIds(rids []int64, isClosed bool, page int) ([]*Issue return []*IssueUser{}, nil } - buf := bytes.NewBufferString("") - for _, rid := range rids { - buf.WriteString("repo_id=") - buf.WriteString(com.ToStr(rid)) - buf.WriteString(" OR ") - } - cond := strings.TrimSuffix(buf.String(), " OR ") ius := make([]*IssueUser, 0, 10) - sess := x.Limit(20, (page-1)*20).Where("is_closed=?", isClosed) - if len(cond) > 0 { - sess.And(cond) - } + sess := x.Limit(20, (page-1)*20).Where("is_closed=?", isClosed).In("repo_id", rids) err := sess.Find(&ius) return ius, err } |