From c0f4675a68278ce648cdefe73b7b6b65327ed89a Mon Sep 17 00:00:00 2001 From: jaqra <48099350+jaqra@users.noreply.github.com> Date: Tue, 5 Nov 2019 09:48:51 +0300 Subject: [PATCH] Fix (open/closed) issue count when label excluded (#8815) * Fix (open/closed) issue count when label excluded * Use capital sql keywords --- models/issue.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/issue.go b/models/issue.go index 78413468b2..1e9d973186 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1293,8 +1293,12 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) { log.Warn("Malformed Labels argument: %s", opts.Labels) } else { for i, labelID := range labelIDs { - 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)) + 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) + } } } }