summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2017-02-25 09:27:39 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-02-25 09:27:39 +0800
commitf1412142e005fef97cf3216c045b24d6cde36de5 (patch)
tree3a9497ec3b4f258cc3725e66d90cfa94b0840c7f /models
parentc0ea3963be91dbd1f436d390ce5223c7ad116479 (diff)
downloadgitea-f1412142e005fef97cf3216c045b24d6cde36de5.tar.gz
gitea-f1412142e005fef97cf3216c045b24d6cde36de5.zip
refactor: repo counts for SearchRepositoryByName func (#1045)
Diffstat (limited to 'models')
-rw-r--r--models/repo.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/models/repo.go b/models/repo.go
index 3a1f149199..c79c52d682 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1834,7 +1834,7 @@ 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) {
+func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, count int64, err error) {
var (
sess *xorm.Session
cond = builder.NewCond()
@@ -1870,7 +1870,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
var ownerIds []int64
ownerIds = append(ownerIds, opts.Searcher.ID)
- err := opts.Searcher.GetOrganizations(true)
+ err = opts.Searcher.GetOrganizations(true)
if err != nil {
return nil, 0, fmt.Errorf("Organization: %v", err)
@@ -1891,15 +1891,21 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
sess = x.
Join("INNER", "star", "star.repo_id = repository.id").
Where(cond)
+ count, err = x.
+ Join("INNER", "star", "star.repo_id = repository.id").
+ Where(cond).
+ Count(new(Repository))
+ if err != nil {
+ return nil, 0, fmt.Errorf("Count: %v", err)
+ }
} else {
sess = x.Where(cond)
- }
-
- var countSess xorm.Session
- countSess = *sess
- count, err := countSess.Count(new(Repository))
- if err != nil {
- return nil, 0, fmt.Errorf("Count: %v", err)
+ count, err = x.
+ Where(cond).
+ Count(new(Repository))
+ if err != nil {
+ return nil, 0, fmt.Errorf("Count: %v", err)
+ }
}
if err = sess.
@@ -1915,7 +1921,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
}
}
- return repos, count, nil
+ return
}
// DeleteRepositoryArchives deletes all repositories' archives.