diff options
author | Jason Song <i@wolfogre.com> | 2022-12-06 15:53:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 15:53:09 +0800 |
commit | 74874d065f39bb381ce6f703388eb4a7dd936509 (patch) | |
tree | 97ae021618551488fd6b551b294630894983dfe8 /services/issue | |
parent | 77f50356f4dd108b1e35b1a706269573aeaf98f1 (diff) | |
download | gitea-74874d065f39bb381ce6f703388eb4a7dd936509.tar.gz gitea-74874d065f39bb381ce6f703388eb4a7dd936509.zip |
Fix issue/PR numbers (#22037)
When deleting a closed issue, we should update both `NumIssues`and
`NumClosedIssues`, or `NumOpenIssues`(`= NumIssues -NumClosedIssues`)
will be wrong. It's the same for pull requests.
Releated to #21557.
Alse fixed two harmless problems:
- The SQL to check issue/PR total numbers is wrong, that means it will
update the numbers even if they are correct.
- Replace legacy `num_issues = num_issues + 1` operations with
`UpdateRepoIssueNumbers`.
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/issue.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go index 5073dff819..b91ee4fc18 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -218,9 +218,16 @@ func deleteIssue(issue *issues_model.Issue) error { return err } - if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, issue.IsClosed); err != nil { + // update the total issue numbers + if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, false); err != nil { return err } + // if the issue is closed, update the closed issue numbers + if issue.IsClosed { + if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, true); err != nil { + return err + } + } if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil { return fmt.Errorf("error updating counters for milestone id %d: %w", |