From 208cc082ad46b0fa9a349d4573658cd6bfb16ac4 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Sun, 19 Jul 2020 21:46:03 +0900 Subject: [PATCH 01/20] Improved total count of issue when filtered. --- models/issue.go | 10 ++++++ routers/api/v1/repo/issue.go | 59 +++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/models/issue.go b/models/issue.go index 1a4de26b3a5d..dce654c3d5da 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1240,6 +1240,16 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { return issues, nil } +// Number return of issues by given conditions. +func CountIssues(opts *IssuesOptions) (int64, error) { + sess := x.NewSession() + defer sess.Close() + + opts.setupSession(sess.Select("COUNT(*)").Table("issue")) + + return sess.Count() +} + // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, // but skips joining with `user` for performance reasons. // User permissions must be verified elsewhere if required. diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index d7bd3cd356db..2ce74af336c3 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -120,6 +120,7 @@ func SearchIssues(ctx *context.APIContext) { } var issues []*models.Issue + var filteredCount int64 keyword := strings.Trim(ctx.Query("q"), " ") if strings.IndexByte(keyword, 0) >= 0 { @@ -165,14 +166,32 @@ func SearchIssues(ctx *context.APIContext) { PriorityRepoID: ctx.QueryInt64("priority_repo_id"), IsPull: isPull, }) - } + if err != nil { + ctx.Error(http.StatusInternalServerError, "Issues", err) + return + } - if err != nil { - ctx.Error(http.StatusInternalServerError, "Issues", err) - return + filteredCount, err = models.CountIssues(&models.IssuesOptions{ + ListOptions: models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: issueCount, + }, + + RepoIDs: repoIDs, + IsClosed: isClosed, + IssueIDs: issueIDs, + IncludedLabelNames: includedLabelNames, + SortType: "priorityrepo", + PriorityRepoID: ctx.QueryInt64("priority_repo_id"), + IsPull: isPull, + }) + if err != nil { + ctx.Error(http.StatusInternalServerError, "CountIssues", err) + return + } } - ctx.SetLinkHeader(issueCount, setting.UI.IssuePagingNum) + ctx.SetLinkHeader(int(filteredCount), setting.UI.IssuePagingNum) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues)) } @@ -239,6 +258,7 @@ func ListIssues(ctx *context.APIContext) { } var issues []*models.Issue + var filteredCount int64 keyword := strings.Trim(ctx.Query("q"), " ") if strings.IndexByte(keyword, 0) >= 0 { @@ -313,15 +333,32 @@ func ListIssues(ctx *context.APIContext) { MilestoneIDs: mileIDs, IsPull: isPull, }) - } + if err != nil { + ctx.Error(http.StatusInternalServerError, "Issues", err) + return + } - if err != nil { - ctx.Error(http.StatusInternalServerError, "Issues", err) - return + filteredCount, err = models.CountIssues(&models.IssuesOptions{ + ListOptions: models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: ctx.Repo.Repository.NumIssues, + }, + + RepoIDs: []int64{ctx.Repo.Repository.ID}, + IsClosed: isClosed, + IssueIDs: issueIDs, + LabelIDs: labelIDs, + MilestoneIDs: mileIDs, + IsPull: isPull, + }) + if err != nil { + ctx.Error(http.StatusInternalServerError, "CountIssues", err) + return + } } - ctx.SetLinkHeader(ctx.Repo.Repository.NumIssues, listOptions.PageSize) - ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", ctx.Repo.Repository.NumIssues)) + ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize) + ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount)) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues)) } From 19dd5779b3622b3d0bdb3d08d088bd57d522814e Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Sun, 19 Jul 2020 21:48:44 +0900 Subject: [PATCH 02/20] Fixed size of slice when selected 1 repository. --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index dce654c3d5da..eb1f776d2125 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1227,7 +1227,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { opts.setupSession(sess) sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID) - issues := make([]*Issue, 0, setting.UI.IssuePagingNum) + issues := make([]*Issue, 0, opts.ListOptions.PageSize) if err := sess.Find(&issues); err != nil { return nil, fmt.Errorf("Find: %v", err) } From bd69a4bdc1a5a123a9f99b9b069d64c478d05ad5 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Sun, 19 Jul 2020 21:51:05 +0900 Subject: [PATCH 03/20] Improved function of error check. --- routers/api/v1/repo/issue.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 2ce74af336c3..56697200f062 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -131,6 +131,10 @@ func SearchIssues(ctx *context.APIContext) { var err error if len(keyword) > 0 && len(repoIDs) > 0 { issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword) + if err != nil { + ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err) + return + } } var isPull util.OptionalBool @@ -269,6 +273,10 @@ func ListIssues(ctx *context.APIContext) { var err error if len(keyword) > 0 { issueIDs, err = issue_indexer.SearchIssuesByKeyword([]int64{ctx.Repo.Repository.ID}, keyword) + if err != nil { + ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err) + return + } } if splitted := strings.Split(ctx.Query("labels"), ","); len(splitted) > 0 { From da583f7553eaa2025945e9e84d2fa8e0058793bf Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Sun, 19 Jul 2020 22:42:15 +0900 Subject: [PATCH 04/20] improved comment --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index eb1f776d2125..7123721586bb 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1240,7 +1240,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { return issues, nil } -// Number return of issues by given conditions. +// CountIssues number return of issues by given conditions. func CountIssues(opts *IssuesOptions) (int64, error) { sess := x.NewSession() defer sess.Close() From 8d0a2de3c51788052d8ddede0441151cf3e4c165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20iCHiGx0f=2Ehino?= =?UTF-8?q?shiba?= Date: Mon, 20 Jul 2020 21:41:05 +0900 Subject: [PATCH 05/20] Added parameter of return header. Co-authored-by: 6543 <6543@obermui.de> --- routers/api/v1/repo/issue.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 56697200f062..10d6b24d0bb3 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -196,6 +196,7 @@ func SearchIssues(ctx *context.APIContext) { } ctx.SetLinkHeader(int(filteredCount), setting.UI.IssuePagingNum) + ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount)) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues)) } From 3f099650f75e7723b6d19616dea464d4e0840e85 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Mon, 20 Jul 2020 21:45:01 +0900 Subject: [PATCH 06/20] Updated corresponded to the current vendored of "xorm.io/xorm". --- models/issue.go | 18 ++++++++++++++++-- routers/api/v1/repo/issue.go | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/models/issue.go b/models/issue.go index 7123721586bb..7e42854df0be 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1245,9 +1245,23 @@ func CountIssues(opts *IssuesOptions) (int64, error) { sess := x.NewSession() defer sess.Close() - opts.setupSession(sess.Select("COUNT(*)").Table("issue")) + var cnt int64 + countsSlice := make([]*struct { + RepoID int64 + Count int64 + }, 0, len(opts.RepoIDs)) + + sess.GroupBy("issue.repo_id"). + Select("issue.repo_id AS repo_id, COUNT(*) AS count").Table("issue") + opts.setupSession(sess) + if err := sess.Find(&countsSlice); err != nil { + return 0, fmt.Errorf("Find: %v", err) + } - return sess.Count() + for _, c := range countsSlice { + cnt += c.Count + } + return cnt, nil } // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 56697200f062..04e2ac5e38d8 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -177,7 +177,7 @@ func SearchIssues(ctx *context.APIContext) { filteredCount, err = models.CountIssues(&models.IssuesOptions{ ListOptions: models.ListOptions{ - Page: ctx.QueryInt("page"), + Page: 0, PageSize: issueCount, }, @@ -196,6 +196,7 @@ func SearchIssues(ctx *context.APIContext) { } ctx.SetLinkHeader(int(filteredCount), setting.UI.IssuePagingNum) + ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount)) ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues)) } @@ -348,7 +349,7 @@ func ListIssues(ctx *context.APIContext) { filteredCount, err = models.CountIssues(&models.IssuesOptions{ ListOptions: models.ListOptions{ - Page: ctx.QueryInt("page"), + Page: 0, PageSize: ctx.Repo.Repository.NumIssues, }, From 0211cb5bffc86541cd7c2e9279c737da430992e8 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Mon, 20 Jul 2020 22:13:20 +0900 Subject: [PATCH 07/20] Dedublicated it by store the Options Struct into a variable. --- routers/api/v1/repo/issue.go | 60 ++++++++++++++---------------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 04e2ac5e38d8..9b067bab3cd4 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -156,12 +156,7 @@ func SearchIssues(ctx *context.APIContext) { // 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(labelIDs) > 0 { - issues, err = models.Issues(&models.IssuesOptions{ - ListOptions: models.ListOptions{ - Page: ctx.QueryInt("page"), - PageSize: setting.UI.IssuePagingNum, - }, - + issuesOpt := &models.IssuesOptions{ RepoIDs: repoIDs, IsClosed: isClosed, IssueIDs: issueIDs, @@ -169,26 +164,23 @@ func SearchIssues(ctx *context.APIContext) { SortType: "priorityrepo", PriorityRepoID: ctx.QueryInt64("priority_repo_id"), IsPull: isPull, - }) + } + + issuesOpt.ListOptions = models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: setting.UI.IssuePagingNum, + } + issues, err = models.Issues(issuesOpt) if err != nil { ctx.Error(http.StatusInternalServerError, "Issues", err) return } - filteredCount, err = models.CountIssues(&models.IssuesOptions{ - ListOptions: models.ListOptions{ - Page: 0, - PageSize: issueCount, - }, - - RepoIDs: repoIDs, - IsClosed: isClosed, - IssueIDs: issueIDs, - IncludedLabelNames: includedLabelNames, - SortType: "priorityrepo", - PriorityRepoID: ctx.QueryInt64("priority_repo_id"), - IsPull: isPull, - }) + issuesOpt.ListOptions = models.ListOptions{ + Page: 0, + PageSize: issueCount, + } + filteredCount, err = models.CountIssues(issuesOpt) if err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) return @@ -333,33 +325,27 @@ func ListIssues(ctx *context.APIContext) { // 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(labelIDs) > 0 { - issues, err = models.Issues(&models.IssuesOptions{ - ListOptions: listOptions, + issuesOpt := &models.IssuesOptions{ RepoIDs: []int64{ctx.Repo.Repository.ID}, IsClosed: isClosed, IssueIDs: issueIDs, LabelIDs: labelIDs, MilestoneIDs: mileIDs, IsPull: isPull, - }) + } + + issuesOpt.ListOptions = listOptions + issues, err = models.Issues(issuesOpt) if err != nil { ctx.Error(http.StatusInternalServerError, "Issues", err) return } - filteredCount, err = models.CountIssues(&models.IssuesOptions{ - ListOptions: models.ListOptions{ - Page: 0, - PageSize: ctx.Repo.Repository.NumIssues, - }, - - RepoIDs: []int64{ctx.Repo.Repository.ID}, - IsClosed: isClosed, - IssueIDs: issueIDs, - LabelIDs: labelIDs, - MilestoneIDs: mileIDs, - IsPull: isPull, - }) + issuesOpt.ListOptions = models.ListOptions{ + Page: 0, + PageSize: ctx.Repo.Repository.NumIssues, + } + filteredCount, err = models.CountIssues(issuesOpt) if err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) return From bc8cc31727f7f5466e898a2f6e30a346c5426ee9 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 22 Jul 2020 17:44:27 +0200 Subject: [PATCH 08/20] format code --- routers/api/v1/repo/issue.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 9b067bab3cd4..b5faa8235c14 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -130,8 +130,7 @@ func SearchIssues(ctx *context.APIContext) { var labelIDs []int64 var err error if len(keyword) > 0 && len(repoIDs) > 0 { - issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword) - if err != nil { + if issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword); err != nil { ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err) return } @@ -157,6 +156,10 @@ func SearchIssues(ctx *context.APIContext) { // This would otherwise return all issues if no issues were found by the search. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issuesOpt := &models.IssuesOptions{ + ListOptions: models.ListOptions{ + Page: ctx.QueryInt("page"), + PageSize: setting.UI.IssuePagingNum, + }, RepoIDs: repoIDs, IsClosed: isClosed, IssueIDs: issueIDs, @@ -166,12 +169,7 @@ func SearchIssues(ctx *context.APIContext) { IsPull: isPull, } - issuesOpt.ListOptions = models.ListOptions{ - Page: ctx.QueryInt("page"), - PageSize: setting.UI.IssuePagingNum, - } - issues, err = models.Issues(issuesOpt) - if err != nil { + if issues, err = models.Issues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "Issues", err) return } @@ -180,8 +178,7 @@ func SearchIssues(ctx *context.APIContext) { Page: 0, PageSize: issueCount, } - filteredCount, err = models.CountIssues(issuesOpt) - if err != nil { + if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) return } @@ -326,6 +323,7 @@ func ListIssues(ctx *context.APIContext) { // This would otherwise return all issues if no issues were found by the search. if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 { issuesOpt := &models.IssuesOptions{ + ListOptions: listOptions, RepoIDs: []int64{ctx.Repo.Repository.ID}, IsClosed: isClosed, IssueIDs: issueIDs, @@ -334,9 +332,7 @@ func ListIssues(ctx *context.APIContext) { IsPull: isPull, } - issuesOpt.ListOptions = listOptions - issues, err = models.Issues(issuesOpt) - if err != nil { + if issues, err = models.Issues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "Issues", err) return } @@ -345,8 +341,7 @@ func ListIssues(ctx *context.APIContext) { Page: 0, PageSize: ctx.Repo.Repository.NumIssues, } - filteredCount, err = models.CountIssues(issuesOpt) - if err != nil { + if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) return } @@ -354,7 +349,6 @@ func ListIssues(ctx *context.APIContext) { ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize) ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", filteredCount)) - ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues)) } From 1507022aa9bd3eedfc1ad37a6e9ed10e62c15160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20iCHiGx0f=2Ehino?= =?UTF-8?q?shiba?= Date: Fri, 24 Jul 2020 07:12:11 +0900 Subject: [PATCH 09/20] Update routers/api/v1/repo/issue.go Co-authored-by: 6543 <6543@obermui.de> --- routers/api/v1/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index b5faa8235c14..38f0aaeeedb1 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -338,7 +338,7 @@ func ListIssues(ctx *context.APIContext) { } issuesOpt.ListOptions = models.ListOptions{ - Page: 0, + Page: -1, PageSize: ctx.Repo.Repository.NumIssues, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { From bf89ea7a39706d8374a27f43c22b5dba2b99e94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20iCHiGx0f=2Ehino?= =?UTF-8?q?shiba?= Date: Fri, 24 Jul 2020 07:12:19 +0900 Subject: [PATCH 10/20] Update routers/api/v1/repo/issue.go Co-authored-by: 6543 <6543@obermui.de> --- routers/api/v1/repo/issue.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 38f0aaeeedb1..f404be53a796 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -339,7 +339,6 @@ func ListIssues(ctx *context.APIContext) { issuesOpt.ListOptions = models.ListOptions{ Page: -1, - PageSize: ctx.Repo.Repository.NumIssues, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) From 82d00def6d0c751477bc5c3489f6923764e82154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20iCHiGx0f=2Ehino?= =?UTF-8?q?shiba?= Date: Fri, 24 Jul 2020 07:13:41 +0900 Subject: [PATCH 11/20] Updated number of range. Co-authored-by: 6543 <6543@obermui.de> --- routers/api/v1/repo/issue.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index f404be53a796..35c990ef593e 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -175,7 +175,6 @@ func SearchIssues(ctx *context.APIContext) { } issuesOpt.ListOptions = models.ListOptions{ - Page: 0, PageSize: issueCount, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { From 2d36293c3a9f9b4b250e6c56f5e4fc31e8b01db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20iCHiGx0f=2Ehino?= =?UTF-8?q?shiba?= Date: Fri, 24 Jul 2020 07:13:53 +0900 Subject: [PATCH 12/20] Updated number of range. Co-authored-by: 6543 <6543@obermui.de> --- routers/api/v1/repo/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 35c990ef593e..c4bc272d56a1 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -175,7 +175,7 @@ func SearchIssues(ctx *context.APIContext) { } issuesOpt.ListOptions = models.ListOptions{ - PageSize: issueCount, + Page: -1, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) From 0c3a9d3f1b5591e50f9b547c2c28bc597cfdcfa5 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Fri, 24 Jul 2020 07:21:18 +0900 Subject: [PATCH 13/20] Removed total value. --- routers/api/v1/repo/issue.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index c4bc272d56a1..a699c49a0aee 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -93,7 +93,6 @@ func SearchIssues(ctx *context.APIContext) { opts.AllLimited = true } - issueCount := 0 for page := 1; ; page++ { opts.Page = page repos, count, err := models.SearchRepositoryByName(opts) @@ -107,14 +106,6 @@ func SearchIssues(ctx *context.APIContext) { } log.Trace("Processing next %d repos of %d", len(repos), count) for _, repo := range repos { - switch isClosed { - case util.OptionalBoolTrue: - issueCount += repo.NumClosedIssues - case util.OptionalBoolFalse: - issueCount += repo.NumOpenIssues - case util.OptionalBoolNone: - issueCount += repo.NumIssues - } repoIDs = append(repoIDs, repo.ID) } } From 07d0225c34fb6de84d034aaa73e8a0e6e909c3cf Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Fri, 24 Jul 2020 07:24:33 +0900 Subject: [PATCH 14/20] make fmt --- routers/api/v1/repo/issue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index a699c49a0aee..5122d8e5cf7d 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -166,7 +166,7 @@ func SearchIssues(ctx *context.APIContext) { } issuesOpt.ListOptions = models.ListOptions{ - Page: -1, + Page: -1, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) @@ -328,7 +328,7 @@ func ListIssues(ctx *context.APIContext) { } issuesOpt.ListOptions = models.ListOptions{ - Page: -1, + Page: -1, } if filteredCount, err = models.CountIssues(issuesOpt); err != nil { ctx.Error(http.StatusInternalServerError, "CountIssues", err) From 8335b427dba3cc5e60067d2c78d85948e89a5d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B2=E3=81=AE=E3=81=97=E3=81=B0=20/=20hinoshiba?= Date: Wed, 16 Sep 2020 21:38:11 +0900 Subject: [PATCH 15/20] Improved value of sql. Co-authored-by: zeripath --- models/issue.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/issue.go b/models/issue.go index 737a3d76f259..b27dfd5466f8 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1271,8 +1271,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) { Count int64 }, 0, len(opts.RepoIDs)) - sess.GroupBy("issue.repo_id"). - Select("issue.repo_id AS repo_id, COUNT(*) AS count").Table("issue") + sess.Select("COUNT(issue.id) AS count").Table("issue") opts.setupSession(sess) if err := sess.Find(&countsSlice); err != nil { return 0, fmt.Errorf("Find: %v", err) From 07f1f8ad60e4339a9fb1d6503898ca9fadece237 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Wed, 16 Sep 2020 21:40:36 +0900 Subject: [PATCH 16/20] Improved value of sql. --- models/issue.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/models/issue.go b/models/issue.go index b27dfd5466f8..87e627c3b167 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1265,22 +1265,20 @@ func CountIssues(opts *IssuesOptions) (int64, error) { sess := x.NewSession() defer sess.Close() - var cnt int64 countsSlice := make([]*struct { RepoID int64 Count int64 - }, 0, len(opts.RepoIDs)) + }, 0, 1) sess.Select("COUNT(issue.id) AS count").Table("issue") opts.setupSession(sess) if err := sess.Find(&countsSlice); err != nil { return 0, fmt.Errorf("Find: %v", err) } - - for _, c := range countsSlice { - cnt += c.Count + if len(countsSlice) < 1 { + return 0, fmt.Errorf("No result.") } - return cnt, nil + return countsSlice[0].Count, nil } // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, From 15b7cb2847e03242be56a60f6e605b66c535993a Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Wed, 16 Sep 2020 21:45:06 +0900 Subject: [PATCH 17/20] improved message --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index 87e627c3b167..8fa1e4a4c5ed 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1276,7 +1276,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) { return 0, fmt.Errorf("Find: %v", err) } if len(countsSlice) < 1 { - return 0, fmt.Errorf("No result.") + return 0, fmt.Errorf("Find: No result.") } return countsSlice[0].Count, nil } From dfc545ed1e43eabe8c81023a95a8c1b922056881 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Wed, 16 Sep 2020 21:54:46 +0900 Subject: [PATCH 18/20] improved message --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index 8fa1e4a4c5ed..0551aa52457e 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1276,7 +1276,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) { return 0, fmt.Errorf("Find: %v", err) } if len(countsSlice) < 1 { - return 0, fmt.Errorf("Find: No result.") + return 0, fmt.Errorf("not result.") } return countsSlice[0].Count, nil } From 46c61e40f5277e47c4fa57d4b10e18e606cca168 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Wed, 16 Sep 2020 22:13:23 +0900 Subject: [PATCH 19/20] improved message --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index 0551aa52457e..622e29a659dc 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1276,7 +1276,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) { return 0, fmt.Errorf("Find: %v", err) } if len(countsSlice) < 1 { - return 0, fmt.Errorf("not result.") + return 0, fmt.Errorf("There is less than one result sql record") } return countsSlice[0].Count, nil } From dc15e1f8e3d2c865de3c3371e76e8a810de7d326 Mon Sep 17 00:00:00 2001 From: "s.k.noe@hinoshiba.com" Date: Wed, 16 Sep 2020 22:31:02 +0900 Subject: [PATCH 20/20] fixed message --- models/issue.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issue.go b/models/issue.go index 622e29a659dc..cf1407d50ee7 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1276,7 +1276,7 @@ func CountIssues(opts *IssuesOptions) (int64, error) { return 0, fmt.Errorf("Find: %v", err) } if len(countsSlice) < 1 { - return 0, fmt.Errorf("There is less than one result sql record") + return 0, fmt.Errorf("there is less than one result sql record") } return countsSlice[0].Count, nil }