Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/749 Reviewed-by: lewis <747342561@qq.com>tags/v1.21.12.1
| @@ -210,9 +210,12 @@ type Repository struct { | |||||
| Balance string `xorm:"NOT NULL DEFAULT '0'"` | Balance string `xorm:"NOT NULL DEFAULT '0'"` | ||||
| BlockChainStatus RepoBlockChainStatus `xorm:"NOT NULL DEFAULT 0"` | BlockChainStatus RepoBlockChainStatus `xorm:"NOT NULL DEFAULT 0"` | ||||
| // git clone total count | |||||
| // git clone and git pull total count | |||||
| CloneCnt int64 `xorm:"NOT NULL DEFAULT 0"` | CloneCnt int64 `xorm:"NOT NULL DEFAULT 0"` | ||||
| // only git clone total count | |||||
| GitCloneCnt int64 `xorm:"NOT NULL DEFAULT 0"` | |||||
| CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||||
| UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||||
| @@ -2473,6 +2476,24 @@ func (repo *Repository) IncreaseCloneCnt() { | |||||
| return | return | ||||
| } | } | ||||
| func (repo *Repository) IncreaseGitCloneCnt() { | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| if err := sess.Begin(); err != nil { | |||||
| return | |||||
| } | |||||
| if _, err := sess.Exec("UPDATE `repository` SET git_clone_cnt = git_clone_cnt + 1 WHERE id = ?", repo.ID); err != nil { | |||||
| return | |||||
| } | |||||
| if err := sess.Commit(); err != nil { | |||||
| return | |||||
| } | |||||
| return | |||||
| } | |||||
| func UpdateRepositoryCommitNum(repo *Repository) error { | func UpdateRepositoryCommitNum(repo *Repository) error { | ||||
| if _, err := x.Exec("UPDATE `repository` SET num_commit = ? where id = ?", repo.NumCommit, repo.ID); err != nil { | if _, err := x.Exec("UPDATE `repository` SET num_commit = ? where id = ?", repo.NumCommit, repo.ID); err != nil { | ||||
| return err | return err | ||||
| @@ -317,6 +317,12 @@ func HTTP(ctx *context.Context) { | |||||
| go repo.IncreaseCloneCnt() | go repo.IncreaseCloneCnt() | ||||
| } | } | ||||
| if ctx.Req.Method == "POST" { | |||||
| if strings.HasSuffix(ctx.Req.URL.Path, "git-upload-pack") { | |||||
| go repo.IncreaseGitCloneCnt() | |||||
| } | |||||
| } | |||||
| w := ctx.Resp | w := ctx.Resp | ||||
| r := ctx.Req.Request | r := ctx.Req.Request | ||||
| cfg := &serviceConfig{ | cfg := &serviceConfig{ | ||||
| @@ -1,13 +1,27 @@ | |||||
| package repo | package repo | ||||
| import ( | import ( | ||||
| "fmt" | |||||
| "net/http" | |||||
| "time" | "time" | ||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/context" | |||||
| "code.gitea.io/gitea/modules/git" | "code.gitea.io/gitea/modules/git" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| ) | ) | ||||
| func QueryUserStaticData(ctx *context.Context) { | |||||
| startDate := ctx.Query("startDate") | |||||
| endDate := ctx.Query("endDate") | |||||
| log.Info("startDate=" + startDate + " endDate=" + endDate) | |||||
| startTime, _ := time.Parse("2006-01-02", startDate) | |||||
| endTime, _ := time.Parse("2006-01-02", endDate) | |||||
| log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) | |||||
| ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix())) | |||||
| } | |||||
| func TimingCountDataByDate(date string) { | func TimingCountDataByDate(date string) { | ||||
| t, _ := time.Parse("2006-01-02", date) | t, _ := time.Parse("2006-01-02", date) | ||||
| @@ -791,7 +791,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) | }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) | ||||
| m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) | m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) | ||||
| m.Get("/tool/query_user_static", repo.QueryUserStaticData) | |||||
| // Grouping for those endpoints not requiring authentication | // Grouping for those endpoints not requiring authentication | ||||
| m.Group("/:username/:reponame", func() { | m.Group("/:username/:reponame", func() { | ||||
| m.Group("/milestone", func() { | m.Group("/milestone", func() { | ||||