diff --git a/models/repo.go b/models/repo.go index 5b527e3cd..625203c74 100755 --- a/models/repo.go +++ b/models/repo.go @@ -2972,3 +2972,12 @@ func OperateRepoModelNum(repoId int64, amount int64, engines ...*xorm.Engine) er func OperateRepoAITaskNum(repoId int64, amount int64, engines ...*xorm.Engine) error { return operateRepoCol(repoId, "ai_task_cnt", amount, engines...) } + +func UpdateRepositoryLastFourMonthCommits(repoID int64, amount int64) error { + _, err := x.Exec("update repository set last_four_month_commits = ? where id = ?", amount, repoID) + return err +} +func UpdateRepositoryLastMonthVisits(repoID int64, amount int64) error { + _, err := x.Exec("update repository set last_month_visits = ? where id = ?", amount, repoID) + return err +} diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index dd73a9f3f..26c3c156d 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -287,20 +287,13 @@ func RepoStatisticDaily(date string) { } func SyncStatDataToRepo(repo *models.Repository) { - changed := false //Save the visit number of repository in the last month if lv, err := models.SumLastMonthNumVisits(repo.ID); err == nil { - repo.LastMonthVisits = lv - changed = true + models.UpdateRepositoryLastMonthVisits(repo.ID, lv) } //Save the commits number of repository in the last four month if lc, err := models.SumLastFourMonthNumCommits(repo.ID); err == nil { - repo.LastFourMonthCommits = lc - changed = true - } - - if changed { - models.UpdateRepository(repo, false) + models.UpdateRepositoryLastFourMonthCommits(repo.ID, lc) } }