Browse Source

#3169

repo-square:add internal api
fix-1523
chenyifan01 2 years ago
parent
commit
e526cfd817
4 changed files with 25 additions and 12 deletions
  1. +11
    -0
      models/repo.go
  2. +2
    -0
      routers/private/internal.go
  3. +1
    -12
      routers/repo/repo_statistic.go
  4. +11
    -0
      services/repository/square.go

+ 11
- 0
models/repo.go View File

@@ -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)
}
}

+ 2
- 0
routers/private/internal.go View File

@@ -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)
}

+ 1
- 12
routers/repo/repo_statistic.go View File

@@ -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
}


+ 11
- 0
services/repository/square.go View File

@@ -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)
}
}

Loading…
Cancel
Save