-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
support search issues pagination #22704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,9 +189,18 @@ func SearchIssues(ctx *context.APIContext) { | |
if strings.IndexByte(keyword, 0) >= 0 { | ||
keyword = "" | ||
} | ||
// this api is also used in UI, | ||
// so the default limit is set to fit UI needs | ||
limit := ctx.FormInt("limit") | ||
if limit == 0 { | ||
limit = setting.UI.IssuePagingNum | ||
} else if limit > setting.API.MaxResponseItems { | ||
limit = setting.API.MaxResponseItems | ||
} | ||
|
||
var issueIDs []int64 | ||
if len(keyword) > 0 && len(repoIDs) > 0 { | ||
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, repoIDs, keyword); err != nil { | ||
if filteredCount, issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, repoIDs, keyword, limit*ctx.FormInt("page"), limit); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err) | ||
return | ||
} | ||
|
@@ -219,15 +228,6 @@ func SearchIssues(ctx *context.APIContext) { | |
includedMilestones = strings.Split(milestones, ",") | ||
} | ||
|
||
// this api is also used in UI, | ||
// so the default limit is set to fit UI needs | ||
limit := ctx.FormInt("limit") | ||
if limit == 0 { | ||
limit = setting.UI.IssuePagingNum | ||
} else if limit > setting.API.MaxResponseItems { | ||
limit = setting.API.MaxResponseItems | ||
} | ||
|
||
// Only fetch the issues if we either don't have a keyword or the search returned issues | ||
// This would otherwise return all issues if no issues were found by the search. | ||
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 { | ||
|
@@ -272,12 +272,14 @@ func SearchIssues(ctx *context.APIContext) { | |
return | ||
} | ||
|
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err) | ||
return | ||
if filteredCount == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what circumstances is |
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
@@ -386,8 +388,9 @@ func ListIssues(ctx *context.APIContext) { | |
} | ||
var issueIDs []int64 | ||
var labelIDs []int64 | ||
listOptions := utils.GetListOptions(ctx) | ||
if len(keyword) > 0 { | ||
issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{ctx.Repo.Repository.ID}, keyword) | ||
filteredCount, issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{ctx.Repo.Repository.ID}, keyword, listOptions.Page*listOptions.PageSize, listOptions.PageSize) | ||
if err != nil { | ||
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err) | ||
return | ||
|
@@ -432,8 +435,6 @@ func ListIssues(ctx *context.APIContext) { | |
} | ||
} | ||
|
||
listOptions := utils.GetListOptions(ctx) | ||
|
||
var isPull util.OptionalBool | ||
switch ctx.FormString("type") { | ||
case "pulls": | ||
|
@@ -481,12 +482,14 @@ func ListIssues(ctx *context.APIContext) { | |
return | ||
} | ||
|
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err) | ||
return | ||
if filteredCount == 0 { | ||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err) | ||
return | ||
} | ||
Comment on lines
+485
to
+492
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti | |
|
||
var issueIDs []int64 | ||
if len(keyword) > 0 { | ||
issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{repo.ID}, keyword) | ||
// FIXME: we don't know how many opened/closed | ||
_, issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{repo.ID}, keyword, 0, 50) | ||
if err != nil { | ||
if issue_indexer.IsAvailable() { | ||
ctx.ServerError("issueIndexer.Search", err) | ||
|
@@ -2341,13 +2342,22 @@ func SearchIssues(ctx *context.Context) { | |
var issues []*issues_model.Issue | ||
var filteredCount int64 | ||
|
||
// this api is also used in UI, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer an API |
||
// so the default limit is set to fit UI needs | ||
limit := ctx.FormInt("limit") | ||
if limit == 0 { | ||
limit = setting.UI.IssuePagingNum | ||
} else if limit > setting.API.MaxResponseItems { | ||
limit = setting.API.MaxResponseItems | ||
} | ||
|
||
keyword := ctx.FormTrim("q") | ||
if strings.IndexByte(keyword, 0) >= 0 { | ||
keyword = "" | ||
} | ||
var issueIDs []int64 | ||
if len(keyword) > 0 && len(repoIDs) > 0 { | ||
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, repoIDs, keyword); err != nil { | ||
if filteredCount, issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, repoIDs, keyword, ctx.FormInt("page")*limit, limit); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err.Error()) | ||
return | ||
} | ||
|
@@ -2377,15 +2387,6 @@ func SearchIssues(ctx *context.Context) { | |
|
||
projectID := ctx.FormInt64("project") | ||
|
||
// this api is also used in UI, | ||
// so the default limit is set to fit UI needs | ||
limit := ctx.FormInt("limit") | ||
if limit == 0 { | ||
limit = setting.UI.IssuePagingNum | ||
} else if limit > setting.API.MaxResponseItems { | ||
limit = setting.API.MaxResponseItems | ||
} | ||
|
||
// Only fetch the issues if we either don't have a keyword or the search returned issues | ||
// This would otherwise return all issues if no issues were found by the search. | ||
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 { | ||
|
@@ -2431,12 +2432,14 @@ func SearchIssues(ctx *context.Context) { | |
return | ||
} | ||
|
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err.Error()) | ||
return | ||
if filteredCount == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CountIssues", err.Error()) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
@@ -2489,10 +2492,15 @@ func ListIssues(ctx *context.Context) { | |
if strings.IndexByte(keyword, 0) >= 0 { | ||
keyword = "" | ||
} | ||
listOptions := db.ListOptions{ | ||
Page: ctx.FormInt("page"), | ||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), | ||
} | ||
|
||
var issueIDs []int64 | ||
var labelIDs []int64 | ||
if len(keyword) > 0 { | ||
issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{ctx.Repo.Repository.ID}, keyword) | ||
filteredCount, issueIDs, err = issue_indexer.SearchIssuesByKeyword(ctx, []int64{ctx.Repo.Repository.ID}, keyword, listOptions.Page*listOptions.PageSize, listOptions.PageSize) | ||
if err != nil { | ||
ctx.Error(http.StatusInternalServerError, err.Error()) | ||
return | ||
|
@@ -2539,11 +2547,6 @@ func ListIssues(ctx *context.Context) { | |
|
||
projectID := ctx.FormInt64("project") | ||
|
||
listOptions := db.ListOptions{ | ||
Page: ctx.FormInt("page"), | ||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), | ||
} | ||
|
||
var isPull util.OptionalBool | ||
switch ctx.FormString("type") { | ||
case "pulls": | ||
|
@@ -2592,12 +2595,14 @@ func ListIssues(ctx *context.Context) { | |
return | ||
} | ||
|
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, err.Error()) | ||
return | ||
if filteredCount == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
issuesOpt.ListOptions = db.ListOptions{ | ||
Page: -1, | ||
} | ||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil { | ||
ctx.Error(http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤨
Sounds like a bug report waiting to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines just moved from line 222 - 230