aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2017-02-22 21:15:14 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-22 21:15:14 +0800
commit83b6d032318c7ba082531a9d0060b7109094b828 (patch)
tree4f76f95ea7defa5ae6465f63cdbf8659ee32b744 /models/repo.go
parentd6748284bd6b4424d0e50cb4b952d12c74203960 (diff)
downloadgitea-83b6d032318c7ba082531a9d0060b7109094b828.tar.gz
gitea-83b6d032318c7ba082531a9d0060b7109094b828.zip
fix: Wrong repo list on Explore page if user already loggin. (#1009)
* fix: Wrong repo list on Explore page if user already loggin. * fix: code readable. * fix: declare variable
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go37
1 files changed, 25 insertions, 12 deletions
diff --git a/models/repo.go b/models/repo.go
index 1d4e3dc311..218f15afe5 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -30,6 +30,7 @@ import (
"github.com/Unknwon/cae/zip"
"github.com/Unknwon/com"
+ "github.com/go-xorm/builder"
"github.com/go-xorm/xorm"
version "github.com/mcuadros/go-version"
ini "gopkg.in/ini.v1"
@@ -1797,7 +1798,11 @@ 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 RepositoryList, _ int64, _ error) {
- var sess *xorm.Session
+ var (
+ sess *xorm.Session
+ cond builder.Cond = builder.NewCond()
+ )
+
if len(opts.Keyword) == 0 {
return repos, 0, nil
}
@@ -1810,26 +1815,24 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
repos = make([]*Repository, 0, opts.PageSize)
if opts.Starred && opts.OwnerID > 0 {
- sess = x.
- Join("INNER", "star", "star.repo_id = repository.id").
- Where("star.uid = ?", opts.OwnerID).
- And("lower_name LIKE ?", "%"+opts.Keyword+"%")
- } else {
- sess = x.Where("lower_name LIKE ?", "%"+opts.Keyword+"%")
+ cond = builder.Eq{
+ "star.uid": opts.OwnerID,
+ }
}
+ cond = cond.And(builder.Like{"lower_name", opts.Keyword})
// Append conditions
if !opts.Starred && opts.OwnerID > 0 {
- sess.And("owner_id = ?", opts.OwnerID)
+ cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
}
if !opts.Private {
- sess.And("is_private=?", false)
+ cond = cond.And(builder.Eq{"is_private": false})
}
if opts.Searcher != nil {
+ var ownerIds []int64
- sess.Or("owner_id = ?", opts.Searcher.ID)
-
+ ownerIds = append(ownerIds, opts.Searcher.ID)
err := opts.Searcher.GetOrganizations(true)
if err != nil {
@@ -1837,14 +1840,24 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
}
for _, org := range opts.Searcher.Orgs {
- sess.Or("owner_id = ?", org.ID)
+ ownerIds = append(ownerIds, org.ID)
}
+
+ cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds)))
}
if len(opts.OrderBy) == 0 {
opts.OrderBy = "name ASC"
}
+ if opts.Starred && opts.OwnerID > 0 {
+ sess = x.
+ Join("INNER", "star", "star.repo_id = repository.id").
+ Where(cond)
+ } else {
+ sess = x.Where(cond)
+ }
+
var countSess xorm.Session
countSess = *sess
count, err := countSess.Count(new(Repository))