aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorguillep2k <18600385+guillep2k@users.noreply.github.com>2020-02-15 07:51:25 -0300
committerGitHub <noreply@github.com>2020-02-15 11:51:25 +0100
commit15614a83682f972bbe900cae935fdc47c4e80e2e (patch)
treef62deab22b6c98417920faf914d1cb7f92c0e87f /models/issue.go
parent7e920703f94c4f2782860a72cc6beca5671736f5 (diff)
downloadgitea-15614a83682f972bbe900cae935fdc47c4e80e2e.tar.gz
gitea-15614a83682f972bbe900cae935fdc47c4e80e2e.zip
Divide GetIssueStats query in smaller chunks (#10176)
* Divide GetIssueStats query in smaller chunks * Skip chunking if count is low enough * Fix lint * Define maxQueryParameters * Remove absMaxQueryParameters because of lint * Restart CI * Restart CI Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index 52d22f1509..4c33767d2a 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1352,6 +1352,36 @@ type IssueStatsOptions struct {
// GetIssueStats returns issue statistic information by given conditions.
func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
+ if len(opts.IssueIDs) <= maxQueryParameters {
+ return getIssueStatsChunk(opts, opts.IssueIDs)
+ }
+
+ // If too long a list of IDs is provided, we get the statistics in
+ // smaller chunks and get accumulates. Note: this could potentially
+ // get us invalid results. The alternative is to insert the list of
+ // ids in a temporary table and join from them.
+ accum := &IssueStats{}
+ for i := 0; i < len(opts.IssueIDs); {
+ chunk := i + maxQueryParameters
+ if chunk > len(opts.IssueIDs) {
+ chunk = len(opts.IssueIDs)
+ }
+ stats, err := getIssueStatsChunk(opts, opts.IssueIDs[i:chunk])
+ if err != nil {
+ return nil, err
+ }
+ accum.OpenCount += stats.OpenCount
+ accum.ClosedCount += stats.ClosedCount
+ accum.YourRepositoriesCount += stats.YourRepositoriesCount
+ accum.AssignCount += stats.AssignCount
+ accum.CreateCount += stats.CreateCount
+ accum.OpenCount += stats.MentionCount
+ i = chunk
+ }
+ return accum, nil
+}
+
+func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats, error) {
stats := &IssueStats{}
countSession := func(opts *IssueStatsOptions) *xorm.Session {