diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/pull.go | 10 | ||||
-rw-r--r-- | models/repo.go | 14 |
2 files changed, 11 insertions, 13 deletions
diff --git a/models/pull.go b/models/pull.go index 454a2a18..9db6791b 100644 --- a/models/pull.go +++ b/models/pull.go @@ -620,16 +620,18 @@ func (prs PullRequestList) loadAttributes(e Engine) (err error) { } // Load issues - issueIDs := make([]int64, 0, len(prs)) + set := make(map[int64]*Issue) for i := range prs { - issueIDs = append(issueIDs, prs[i].IssueID) + set[prs[i].IssueID] = nil + } + issueIDs := make([]int64, 0, len(prs)) + for issueID := range set { + issueIDs = append(issueIDs, issueID) } issues := make([]*Issue, 0, len(issueIDs)) if err = e.Where("id > 0").In("id", issueIDs).Find(&issues); err != nil { return fmt.Errorf("find issues: %v", err) } - - set := make(map[int64]*Issue) for i := range issues { set[issues[i].ID] = issues[i] } diff --git a/models/repo.go b/models/repo.go index b48cb1aa..751850d8 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1581,11 +1581,6 @@ type SearchRepoOptions struct { // SearchRepositoryByName takes keyword and part of repository name to search, // it returns results in given range and number of total results. func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int64, _ error) { - if len(opts.Keyword) == 0 { - return repos, 0, nil - } - opts.Keyword = strings.ToLower(opts.Keyword) - if opts.Page <= 0 { opts.Page = 1 } @@ -1596,15 +1591,16 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int // this does not include other people's private repositories even if opts.UserID is an admin. if !opts.Private && opts.UserID > 0 { sess.Join("LEFT", "access", "access.repo_id = repo.id"). - Where("repo.lower_name LIKE ? AND (repo.owner_id = ? OR access.user_id = ? OR repo.is_private = ?)", - "%"+opts.Keyword+"%", opts.UserID, opts.UserID, false) + Where("(repo.owner_id = ? OR access.user_id = ? OR repo.is_private = ?)", opts.UserID, opts.UserID, false) } else { - sess.Where("repo.lower_name LIKE ?", "%"+opts.Keyword+"%") // Only return public repositories if opts.Private is not set if !opts.Private { sess.And("repo.is_private = ?", false) } } + if len(opts.Keyword) > 0 { + sess.And("repo.lower_name LIKE ?", "%"+strings.ToLower(opts.Keyword)+"%") + } if opts.OwnerID > 0 { sess.And("repo.owner_id = ?", opts.OwnerID) } @@ -1949,7 +1945,7 @@ func (repos RepositoryList) loadAttributes(e Engine) error { return nil } - // Load owners. + // Load owners set := make(map[int64]*User) for i := range repos { set[repos[i].OwnerID] = nil |