diff --git a/models/repo.go b/models/repo.go index 4d6fcfd2f..06fec6764 100755 --- a/models/repo.go +++ b/models/repo.go @@ -2994,3 +2994,14 @@ func UpdateRepositoryLastMonthVisits(repoID int64, amount int64) error { _, err := x.Exec("update repository set last_month_visits = ? where id = ?", amount, repoID) return err } + +func SyncStatDataToRepo(repo *Repository) { + //Save the visit number of repository in the last month + if lv, err := SumLastMonthNumVisits(repo.ID); err == nil { + UpdateRepositoryLastMonthVisits(repo.ID, lv) + } + //Save the commits number of repository in the last four month + if lc, err := SumLastFourMonthNumCommits(repo.ID); err == nil { + UpdateRepositoryLastFourMonthCommits(repo.ID, lc) + } +} diff --git a/routers/private/internal.go b/routers/private/internal.go index eae3713a9..0b8ae600a 100755 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -6,6 +6,7 @@ package private import ( + "code.gitea.io/gitea/services/repository" "strings" "code.gitea.io/gitea/routers/admin" @@ -57,6 +58,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) m.Post("/repos/cnt_stat/handle_historical_task", admin.RefreshHistorySpec) m.Post("/duration_statisctic/history_handle", repo.CloudbrainUpdateHistoryData) + m.Post("/square/repo/stat/refresh", repository.RefreshRepoStatData) }, CheckInternalToken) } diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index 26c3c156d..c1a7954a7 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -166,7 +166,7 @@ func RepoStatisticDaily(date string) { repoStat.NumIssuesGrowth = repoStat.NumIssues - repoStatisticFourMonthsAgo.NumIssues } - SyncStatDataToRepo(repo) + models.SyncStatDataToRepo(repo) if _, err = models.InsertRepoStat(&repoStat); err != nil { log.Error("InsertRepoStat failed(%s): %v", projectName, err) @@ -286,17 +286,6 @@ func RepoStatisticDaily(date string) { } -func SyncStatDataToRepo(repo *models.Repository) { - //Save the visit number of repository in the last month - if lv, err := models.SumLastMonthNumVisits(repo.ID); err == nil { - 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 { - models.UpdateRepositoryLastFourMonthCommits(repo.ID, lc) - } -} - func getDistinctProjectName(repo *models.Repository) string { return repo.OwnerName + "/" + repo.Alias } diff --git a/services/repository/square.go b/services/repository/square.go index e07b4fbed..0fc7e6e06 100644 --- a/services/repository/square.go +++ b/services/repository/square.go @@ -295,3 +295,14 @@ func GetActiveOrgs() ([]*models.User4Front, error) { } return orgs, nil } + +func RefreshRepoStatData() { + repos, err := models.GetAllRepositories() + if err != nil { + log.Error("RefreshRepoStatData GetAllRepositories failed: %v", err.Error()) + return + } + for _, repo := range repos { + models.SyncStatDataToRepo(repo) + } +}