diff options
author | Morlinest <morlinest@gmail.com> | 2017-10-10 22:37:18 +0200 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-10-10 22:37:18 +0200 |
commit | dff26e25ca4e088ac709bc4b11eb84cdb9603d34 (patch) | |
tree | 2718eafc36bf69f4915ddf1aa83fe1fcf112d4f5 /models/repo_list.go | |
parent | c2346e44696e57c31f9765c32ee60b365a15c8f0 (diff) | |
download | gitea-dff26e25ca4e088ac709bc4b11eb84cdb9603d34.tar.gz gitea-dff26e25ca4e088ac709bc4b11eb84cdb9603d34.zip |
Remove redudant functions and code (#2652)
* Remove redudant functions and code
Diffstat (limited to 'models/repo_list.go')
-rw-r--r-- | models/repo_list.go | 92 |
1 files changed, 12 insertions, 80 deletions
diff --git a/models/repo_list.go b/models/repo_list.go index ca7ae9793f..4aeda90677 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -105,6 +105,7 @@ type SearchRepoOptions struct { Starred bool `json:"-"` Page int `json:"-"` IsProfile bool `json:"-"` + AllPublic bool `json:"-"` // Include also all public repositories // Limit of result // // maximum: setting.ExplorePagingNum @@ -129,6 +130,8 @@ const ( SearchOrderByNewest = "created_unix DESC" SearchOrderBySize = "size ASC" SearchOrderBySizeReverse = "size DESC" + SearchOrderByID = "id ASC" + SearchOrderByIDReverse = "id DESC" ) // SearchRepositoryByName takes keyword and part of repository name to search, @@ -147,11 +150,6 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun starJoin = true } - opts.Keyword = strings.ToLower(opts.Keyword) - if opts.Keyword != "" { - cond = cond.And(builder.Like{"lower_name", opts.Keyword}) - } - // Append conditions if !opts.Starred && opts.OwnerID > 0 { var searcherReposCond builder.Cond = builder.Eq{"owner_id": opts.OwnerID} @@ -182,6 +180,15 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun cond = cond.And(builder.Eq{"is_private": false}) } + if opts.OwnerID > 0 && opts.AllPublic { + cond = cond.Or(builder.Eq{"is_private": false}) + } + + opts.Keyword = strings.ToLower(opts.Keyword) + if opts.Keyword != "" { + cond = cond.And(builder.Like{"lower_name", opts.Keyword}) + } + if len(opts.OrderBy) == 0 { opts.OrderBy = SearchOrderByAlphabetically } @@ -225,78 +232,3 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun return } - -// Repositories returns all repositories -func Repositories(opts *SearchRepoOptions) (_ RepositoryList, count int64, err error) { - if len(opts.OrderBy) == 0 { - opts.OrderBy = "id ASC" - } - - repos := make(RepositoryList, 0, opts.PageSize) - - if err = x. - Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). - OrderBy(opts.OrderBy.String()). - Find(&repos); err != nil { - return nil, 0, fmt.Errorf("Repo: %v", err) - } - - if err = repos.loadAttributes(x); err != nil { - return nil, 0, fmt.Errorf("LoadAttributes: %v", err) - } - - count = countRepositories(-1, opts.Private) - - return repos, count, nil -} - -// GetRecentUpdatedRepositories returns the list of repositories that are recently updated. -func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList, _ int64, _ error) { - var cond = builder.NewCond() - - if len(opts.OrderBy) == 0 { - opts.OrderBy = SearchOrderByRecentUpdated - } - - if !opts.Private { - cond = builder.Eq{ - "is_private": false, - } - } - - if opts.Searcher != nil && !opts.Searcher.IsAdmin { - var ownerIds []int64 - - ownerIds = append(ownerIds, opts.Searcher.ID) - err := opts.Searcher.GetOrganizations(true) - - if err != nil { - return nil, 0, fmt.Errorf("Organization: %v", err) - } - - for _, org := range opts.Searcher.Orgs { - ownerIds = append(ownerIds, org.ID) - } - - cond = cond.Or(builder.In("owner_id", ownerIds)) - } - - count, err := x.Where(cond).Count(new(Repository)) - if err != nil { - return nil, 0, fmt.Errorf("Count: %v", err) - } - - if err = x.Where(cond). - Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). - Limit(opts.PageSize). - OrderBy(opts.OrderBy.String()). - Find(&repos); err != nil { - return nil, 0, fmt.Errorf("Repo: %v", err) - } - - if err = repos.loadAttributes(x); err != nil { - return nil, 0, fmt.Errorf("LoadAttributes: %v", err) - } - - return repos, count, nil -} |