From 43200e0e67263a537b7e56d4214ee9408006a418 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 10 Nov 2021 14:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=8E=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=90=8E=E6=81=A2=E5=A4=8Dfork=E6=8C=87?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/repo_statistic.go | 7 +++++++ routers/api/v1/api.go | 2 ++ routers/api/v1/repo/repo_dashbord.go | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/models/repo_statistic.go b/models/repo_statistic.go index 9184ab4ec..df065bb79 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -158,6 +158,13 @@ func InsertRepoStat(repoStat *RepoStatistic) (int64, error) { return xStatistic.Insert(repoStat) } +func RestoreRepoStatFork(numForks int64, repoId int64) error { + sql := "update repo_statistic set num_forks=? where repo_id=?" + + _, err := xStatistic.Exec(sql, numForks, repoId) + return err +} + func UpdateRepoStat(repoStat *RepoStatistic) error { sql := "update repo_statistic set impact=?,completeness=?,liveness=?,project_health=?,team_health=?,growth=?,radar_total=? where repo_id=? and date=?" diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index dd744e933..8b068d612 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -527,6 +527,8 @@ func RegisterRoutes(m *macaron.Macaron) { //Project board m.Group("/projectboard", func() { + m.Get("/restoreFork", adminReq, repo.RestoreForkNumber) + m.Group("/project", func() { m.Get("", adminReq, repo.GetAllProjectsPeriodStatistics) m.Group("/:id", func() { diff --git a/routers/api/v1/repo/repo_dashbord.go b/routers/api/v1/repo/repo_dashbord.go index 6759470fb..e48bda50d 100644 --- a/routers/api/v1/repo/repo_dashbord.go +++ b/routers/api/v1/repo/repo_dashbord.go @@ -50,6 +50,19 @@ type ProjectLatestData struct { Top10 []UserInfo `json:"top10"` } +func RestoreForkNumber(ctx *context.Context) { + repos, err := models.GetAllRepositories() + if err != nil { + log.Error("GetAllRepositories failed: %v", err.Error()) + return + } + for _, repo := range repos { + models.RestoreRepoStatFork(int64(repo.NumForks), repo.ID) + } + + ctx.JSON(http.StatusOK, struct{}{}) +} + func GetAllProjectsPeriodStatistics(ctx *context.Context) { recordBeginTime, err := getRecordBeginTime()