summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2022-12-06 15:53:09 +0800
committerGitHub <noreply@github.com>2022-12-06 15:53:09 +0800
commit74874d065f39bb381ce6f703388eb4a7dd936509 (patch)
tree97ae021618551488fd6b551b294630894983dfe8 /models
parent77f50356f4dd108b1e35b1a706269573aeaf98f1 (diff)
downloadgitea-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 'models')
-rw-r--r--models/issues/issue.go7
-rw-r--r--models/repo.go4
2 files changed, 3 insertions, 8 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 1d66996ee0..3ab6d204ba 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -997,12 +997,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
}
}
- if opts.IsPull {
- _, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID)
- } else {
- _, err = e.Exec("UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?", opts.Issue.RepoID)
- }
- if err != nil {
+ if err := repo_model.UpdateRepoIssueNumbers(ctx, opts.Issue.RepoID, opts.IsPull, false); err != nil {
return err
}
diff --git a/models/repo.go b/models/repo.go
index 5d333a3aee..9af600c9ba 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -443,7 +443,7 @@ func CheckRepoStats(ctx context.Context) error {
},
// Repository.NumIssues
{
- statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", false, false),
+ statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_pull=?)", false),
repoStatsCorrectNumIssues,
"repository count 'num_issues'",
},
@@ -455,7 +455,7 @@ func CheckRepoStats(ctx context.Context) error {
},
// Repository.NumPulls
{
- statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", false, true),
+ statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_pull=?)", true),
repoStatsCorrectNumPulls,
"repository count 'num_pulls'",
},