From: Gusted Date: Wed, 12 Oct 2022 06:47:48 +0000 (+0000) Subject: Add Num{Issues,Pulls} stats checks (#21404) (#21414) X-Git-Tag: v1.17.3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d74578001491e70d5db19270a442ece3f2a758aa;p=gitea.git Add Num{Issues,Pulls} stats checks (#21404) (#21414) Backport #21404 Currently `repository.Num{Issues,Pulls}` weren't checked and could become out-of-consistency. Adds these two checks to `CheckRepoStats`. Fix incorrect SQL query for `repository.NumClosedPulls`, the check should be for `repo_num_pulls`. Co-authored-by: wxiaoguang --- diff --git a/models/repo.go b/models/repo.go index d2f3a45940..e304abf960 100644 --- a/models/repo.go +++ b/models/repo.go @@ -605,15 +605,27 @@ func CheckRepoStats(ctx context.Context) error { repoStatsCorrectNumStars, "repository count 'num_stars'", }, + // 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), + repoStatsCorrectNumIssues, + "repository count 'num_issues'", + }, // Repository.NumClosedIssues { statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false), repoStatsCorrectNumClosedIssues, "repository count 'num_closed_issues'", }, + // 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), + repoStatsCorrectNumPulls, + "repository count 'num_pulls'", + }, // Repository.NumClosedPulls { - statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, true), + statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, true), repoStatsCorrectNumClosedPulls, "repository count 'num_closed_pulls'", },