aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issues/issue.go')
-rw-r--r--models/issues/issue.go40
1 files changed, 26 insertions, 14 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 8c173433f2..df38e68519 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -1251,6 +1251,8 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
if opts.AssigneeID > 0 {
applyAssigneeCondition(sess, opts.AssigneeID)
+ } else if opts.AssigneeID == db.NoConditionID {
+ sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
}
if opts.PosterID > 0 {
@@ -1312,13 +1314,17 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()})
}
- if opts.LabelIDs != nil {
- for i, labelID := range opts.LabelIDs {
- if labelID > 0 {
- sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
- fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
- } else {
- sess.Where("issue.id not in (select issue_id from issue_label where label_id = ?)", -labelID)
+ if len(opts.LabelIDs) > 0 {
+ if opts.LabelIDs[0] == 0 {
+ sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label)")
+ } else {
+ for i, labelID := range opts.LabelIDs {
+ if labelID > 0 {
+ sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
+ fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
+ } else if labelID < 0 { // 0 is not supported here, so just ignore it
+ sess.Where("issue.id not in (select issue_id from issue_label where label_id = ?)", -labelID)
+ }
}
}
}
@@ -1705,17 +1711,21 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
sess.In("issue.id", issueIDs)
}
- if len(opts.Labels) > 0 && opts.Labels != "0" {
+ if len(opts.Labels) > 0 {
labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
if err != nil {
log.Warn("Malformed Labels argument: %s", opts.Labels)
} else {
- for i, labelID := range labelIDs {
- if labelID > 0 {
- sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
- fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
- } else {
- sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label WHERE label_id = ?)", -labelID)
+ if labelIDs[0] == 0 {
+ sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label)")
+ } else {
+ for i, labelID := range labelIDs {
+ if labelID > 0 {
+ sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
+ fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
+ } else if labelID < 0 { // 0 is not supported here, so just ignore it
+ sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label WHERE label_id = ?)", -labelID)
+ }
}
}
}
@@ -1734,6 +1744,8 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats,
if opts.AssigneeID > 0 {
applyAssigneeCondition(sess, opts.AssigneeID)
+ } else if opts.AssigneeID == db.NoConditionID {
+ sess.Where("id NOT IN (SELECT issue_id FROM issue_assignees)")
}
if opts.PosterID > 0 {