|
|
@ -120,10 +120,12 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun |
|
|
|
opts.Page = 1 |
|
|
|
opts.Page = 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var starJoin bool |
|
|
|
if opts.Starred && opts.OwnerID > 0 { |
|
|
|
if opts.Starred && opts.OwnerID > 0 { |
|
|
|
cond = builder.Eq{ |
|
|
|
cond = builder.Eq{ |
|
|
|
"star.uid": opts.OwnerID, |
|
|
|
"star.uid": opts.OwnerID, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
starJoin = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
opts.Keyword = strings.ToLower(opts.Keyword) |
|
|
|
opts.Keyword = strings.ToLower(opts.Keyword) |
|
|
@ -133,12 +135,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun |
|
|
|
|
|
|
|
|
|
|
|
// Append conditions
|
|
|
|
// Append conditions
|
|
|
|
if !opts.Starred && opts.OwnerID > 0 { |
|
|
|
if !opts.Starred && opts.OwnerID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) |
|
|
|
var searcherReposCond builder.Cond = builder.Eq{"owner_id": opts.OwnerID} |
|
|
|
} |
|
|
|
|
|
|
|
if !opts.Private { |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"is_private": false}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if opts.Searcher != nil { |
|
|
|
if opts.Searcher != nil { |
|
|
|
var ownerIds []int64 |
|
|
|
var ownerIds []int64 |
|
|
|
|
|
|
|
|
|
|
@ -153,14 +150,19 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun |
|
|
|
ownerIds = append(ownerIds, org.ID) |
|
|
|
ownerIds = append(ownerIds, org.ID) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
searcherReposCond := builder.In("owner_id", ownerIds) |
|
|
|
searcherReposCond = searcherReposCond.Or(builder.In("owner_id", ownerIds)) |
|
|
|
if opts.Collaborate { |
|
|
|
if opts.Collaborate { |
|
|
|
searcherReposCond = searcherReposCond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, |
|
|
|
searcherReposCond = searcherReposCond.Or(builder.Expr("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ? AND owner_id != ?)", |
|
|
|
opts.Searcher.ID, opts.Searcher.ID)) |
|
|
|
opts.Searcher.ID, opts.Searcher.ID)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
cond = cond.And(searcherReposCond) |
|
|
|
cond = cond.And(searcherReposCond) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !opts.Private { |
|
|
|
|
|
|
|
cond = cond.And(builder.Eq{"is_private": false}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(opts.OrderBy) == 0 { |
|
|
|
if len(opts.OrderBy) == 0 { |
|
|
|
opts.OrderBy = "name ASC" |
|
|
|
opts.OrderBy = "name ASC" |
|
|
|
} |
|
|
|
} |
|
|
@ -168,7 +170,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun |
|
|
|
sess := x.NewSession() |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
defer sess.Close() |
|
|
|
|
|
|
|
|
|
|
|
if opts.Starred && opts.OwnerID > 0 { |
|
|
|
if starJoin { |
|
|
|
count, err = sess. |
|
|
|
count, err = sess. |
|
|
|
Join("INNER", "star", "star.repo_id = repository.id"). |
|
|
|
Join("INNER", "star", "star.repo_id = repository.id"). |
|
|
|
Where(cond). |
|
|
|
Where(cond). |
|
|
|