Skip to content

Commit b658f2c

Browse files
authored
Return empty when searching issues with no repos (#26545)
1 parent 47fddaa commit b658f2c

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

routers/api/v1/repo/issue.go

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func SearchIssues(ctx *context.APIContext) {
193193
ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err)
194194
return
195195
}
196+
if len(repoIDs) == 0 {
197+
// no repos found, don't let the indexer return all repos
198+
repoIDs = []int64{0}
199+
}
196200
}
197201

198202
keyword := ctx.FormTrim("q")

routers/web/repo/issue.go

+4
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,10 @@ func SearchIssues(ctx *context.Context) {
25032503
ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err.Error())
25042504
return
25052505
}
2506+
if len(repoIDs) == 0 {
2507+
// no repos found, don't let the indexer return all repos
2508+
repoIDs = []int64{0}
2509+
}
25062510
}
25072511

25082512
keyword := ctx.FormTrim("q")

routers/web/user/home.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,21 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
454454
AllPublic: false,
455455
AllLimited: false,
456456
}
457-
458457
if team != nil {
459458
repoOpts.TeamID = team.ID
460459
}
460+
{
461+
ids, _, err := repo_model.SearchRepositoryIDs(repoOpts)
462+
if err != nil {
463+
ctx.ServerError("SearchRepositoryIDs", err)
464+
return
465+
}
466+
opts.RepoIDs = ids
467+
if len(opts.RepoIDs) == 0 {
468+
// no repos found, don't let the indexer return all repos
469+
opts.RepoIDs = []int64{0}
470+
}
471+
}
461472

462473
switch filterMode {
463474
case issues_model.FilterModeAll:
@@ -541,15 +552,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
541552
// Parse ctx.FormString("repos") and remember matched repo IDs for later.
542553
// Gets set when clicking filters on the issues overview page.
543554
repoIDs := getRepoIDs(ctx.FormString("repos"))
544-
if len(repoIDs) == 0 {
545-
repoIDs = accessibleRepos.Values()
546-
} else {
555+
if len(repoIDs) > 0 {
547556
// Remove repo IDs that are not accessible to the user.
548557
repoIDs = util.SliceRemoveAllFunc(repoIDs, func(v int64) bool {
549558
return !accessibleRepos.Contains(v)
550559
})
560+
opts.RepoIDs = repoIDs
551561
}
552-
opts.RepoIDs = repoIDs
553562

554563
// ------------------------------
555564
// Get issues as defined by opts.
@@ -609,6 +618,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
609618
var issueStats *issues_model.IssueStats
610619
{
611620
statsOpts := issues_model.IssuesOptions{
621+
RepoIDs: repoIDs,
612622
User: ctx.Doer,
613623
IsPull: util.OptionalBoolOf(isPullList),
614624
IsClosed: util.OptionalBoolOf(isShowClosed),

0 commit comments

Comments
 (0)