|
|
@ -1352,6 +1352,36 @@ type IssueStatsOptions struct { |
|
|
|
|
|
|
|
|
|
|
|
// GetIssueStats returns issue statistic information by given conditions.
|
|
|
|
// GetIssueStats returns issue statistic information by given conditions.
|
|
|
|
func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) { |
|
|
|
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{} |
|
|
|
stats := &IssueStats{} |
|
|
|
|
|
|
|
|
|
|
|
countSession := func(opts *IssueStatsOptions) *xorm.Session { |
|
|
|
countSession := func(opts *IssueStatsOptions) *xorm.Session { |
|
|
|