@@ -116,68 +116,69 @@ func GetIssueStats(opts *IssuesOptions) (*IssueStats, error) {
116
116
func getIssueStatsChunk (opts * IssuesOptions , issueIDs []int64 ) (* IssueStats , error ) {
117
117
stats := & IssueStats {}
118
118
119
- countSession := func (opts * IssuesOptions , issueIDs []int64 ) * xorm.Session {
120
- sess := db .GetEngine (db .DefaultContext ).
121
- Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
122
- if len (opts .RepoIDs ) > 1 {
123
- sess .In ("issue.repo_id" , opts .RepoIDs )
124
- } else if len (opts .RepoIDs ) == 1 {
125
- sess .And ("issue.repo_id = ?" , opts .RepoIDs [0 ])
126
- }
119
+ sess := db .GetEngine (db .DefaultContext ).
120
+ Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
127
121
128
- if len (issueIDs ) > 0 {
129
- sess .In ("issue.id" , issueIDs )
130
- }
122
+ var err error
123
+ stats .OpenCount , err = applyIssuesOptions (sess , opts , issueIDs ).
124
+ And ("issue.is_closed = ?" , false ).
125
+ Count (new (Issue ))
126
+ if err != nil {
127
+ return stats , err
128
+ }
129
+ stats .ClosedCount , err = applyIssuesOptions (sess , opts , issueIDs ).
130
+ And ("issue.is_closed = ?" , true ).
131
+ Count (new (Issue ))
132
+ return stats , err
133
+ }
131
134
132
- applyLabelsCondition (sess , opts )
135
+ func applyIssuesOptions (sess * xorm.Session , opts * IssuesOptions , issueIDs []int64 ) * xorm.Session {
136
+ if len (opts .RepoIDs ) > 1 {
137
+ sess .In ("issue.repo_id" , opts .RepoIDs )
138
+ } else if len (opts .RepoIDs ) == 1 {
139
+ sess .And ("issue.repo_id = ?" , opts .RepoIDs [0 ])
140
+ }
133
141
134
- applyMilestoneCondition (sess , opts )
142
+ if len (issueIDs ) > 0 {
143
+ sess .In ("issue.id" , issueIDs )
144
+ }
135
145
136
- applyProjectCondition (sess , opts )
146
+ applyLabelsCondition (sess , opts )
137
147
138
- if opts .AssigneeID > 0 {
139
- applyAssigneeCondition (sess , opts .AssigneeID )
140
- } else if opts .AssigneeID == db .NoConditionID {
141
- sess .Where ("issue.id NOT IN (SELECT issue_id FROM issue_assignees)" )
142
- }
148
+ applyMilestoneCondition (sess , opts )
143
149
144
- if opts .PosterID > 0 {
145
- applyPosterCondition (sess , opts .PosterID )
146
- }
150
+ applyProjectCondition (sess , opts )
147
151
148
- if opts .MentionedID > 0 {
149
- applyMentionedCondition (sess , opts .MentionedID )
150
- }
152
+ if opts .AssigneeID > 0 {
153
+ applyAssigneeCondition (sess , opts .AssigneeID )
154
+ } else if opts .AssigneeID == db .NoConditionID {
155
+ sess .Where ("issue.id NOT IN (SELECT issue_id FROM issue_assignees)" )
156
+ }
151
157
152
- if opts .ReviewRequestedID > 0 {
153
- applyReviewRequestedCondition (sess , opts .ReviewRequestedID )
154
- }
158
+ if opts .PosterID > 0 {
159
+ applyPosterCondition (sess , opts .PosterID )
160
+ }
155
161
156
- if opts .ReviewedID > 0 {
157
- applyReviewedCondition (sess , opts .ReviewedID )
158
- }
162
+ if opts .MentionedID > 0 {
163
+ applyMentionedCondition (sess , opts .MentionedID )
164
+ }
159
165
160
- switch opts .IsPull {
161
- case util .OptionalBoolTrue :
162
- sess .And ("issue.is_pull=?" , true )
163
- case util .OptionalBoolFalse :
164
- sess .And ("issue.is_pull=?" , false )
165
- }
166
+ if opts .ReviewRequestedID > 0 {
167
+ applyReviewRequestedCondition (sess , opts .ReviewRequestedID )
168
+ }
166
169
167
- return sess
170
+ if opts .ReviewedID > 0 {
171
+ applyReviewedCondition (sess , opts .ReviewedID )
168
172
}
169
173
170
- var err error
171
- stats .OpenCount , err = countSession (opts , issueIDs ).
172
- And ("issue.is_closed = ?" , false ).
173
- Count (new (Issue ))
174
- if err != nil {
175
- return stats , err
174
+ switch opts .IsPull {
175
+ case util .OptionalBoolTrue :
176
+ sess .And ("issue.is_pull=?" , true )
177
+ case util .OptionalBoolFalse :
178
+ sess .And ("issue.is_pull=?" , false )
176
179
}
177
- stats .ClosedCount , err = countSession (opts , issueIDs ).
178
- And ("issue.is_closed = ?" , true ).
179
- Count (new (Issue ))
180
- return stats , err
180
+
181
+ return sess
181
182
}
182
183
183
184
// GetUserIssueStats returns issue statistic information for dashboard by given conditions.
0 commit comments