| @@ -2994,3 +2994,14 @@ func UpdateRepositoryLastMonthVisits(repoID int64, amount int64) error { | |||||
| _, err := x.Exec("update repository set last_month_visits = ? where id = ?", amount, repoID) | _, err := x.Exec("update repository set last_month_visits = ? where id = ?", amount, repoID) | ||||
| return err | 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) | |||||
| } | |||||
| } | |||||
| @@ -6,6 +6,7 @@ | |||||
| package private | package private | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/services/repository" | |||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/routers/admin" | "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("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | ||||
| m.Post("/repos/cnt_stat/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("/duration_statisctic/history_handle", repo.CloudbrainUpdateHistoryData) | ||||
| m.Post("/square/repo/stat/refresh", repository.RefreshRepoStatData) | |||||
| }, CheckInternalToken) | }, CheckInternalToken) | ||||
| } | } | ||||
| @@ -166,7 +166,7 @@ func RepoStatisticDaily(date string) { | |||||
| repoStat.NumIssuesGrowth = repoStat.NumIssues - repoStatisticFourMonthsAgo.NumIssues | repoStat.NumIssuesGrowth = repoStat.NumIssues - repoStatisticFourMonthsAgo.NumIssues | ||||
| } | } | ||||
| SyncStatDataToRepo(repo) | |||||
| models.SyncStatDataToRepo(repo) | |||||
| if _, err = models.InsertRepoStat(&repoStat); err != nil { | if _, err = models.InsertRepoStat(&repoStat); err != nil { | ||||
| log.Error("InsertRepoStat failed(%s): %v", projectName, err) | 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 { | func getDistinctProjectName(repo *models.Repository) string { | ||||
| return repo.OwnerName + "/" + repo.Alias | return repo.OwnerName + "/" + repo.Alias | ||||
| } | } | ||||
| @@ -295,3 +295,14 @@ func GetActiveOrgs() ([]*models.User4Front, error) { | |||||
| } | } | ||||
| return orgs, nil | 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) | |||||
| } | |||||
| } | |||||