Browse Source

Merge pull request '增加用户看板界面查询接口及git clone下载次数纠正功能。 对应: #748, #595' (#749) from zouap_static into V20211115

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/749
Reviewed-by: lewis <747342561@qq.com>
tags/v1.21.12.1
lewis 4 years ago
parent
commit
79d57af038
4 changed files with 43 additions and 2 deletions
  1. +22
    -1
      models/repo.go
  2. +6
    -0
      routers/repo/http.go
  3. +14
    -0
      routers/repo/user_data_analysis.go
  4. +1
    -1
      routers/routes/routes.go

+ 22
- 1
models/repo.go View File

@@ -210,9 +210,12 @@ type Repository struct {
Balance string `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"`

// only git clone total count
GitCloneCnt int64 `xorm:"NOT NULL DEFAULT 0"`

CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

@@ -2473,6 +2476,24 @@ func (repo *Repository) IncreaseCloneCnt() {
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 {
if _, err := x.Exec("UPDATE `repository` SET num_commit = ? where id = ?", repo.NumCommit, repo.ID); err != nil {
return err


+ 6
- 0
routers/repo/http.go View File

@@ -317,6 +317,12 @@ func HTTP(ctx *context.Context) {
go repo.IncreaseCloneCnt()
}

if ctx.Req.Method == "POST" {
if strings.HasSuffix(ctx.Req.URL.Path, "git-upload-pack") {
go repo.IncreaseGitCloneCnt()
}
}

w := ctx.Resp
r := ctx.Req.Request
cfg := &serviceConfig{


+ 14
- 0
routers/repo/user_data_analysis.go View File

@@ -1,13 +1,27 @@
package repo

import (
"fmt"
"net/http"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"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) {

t, _ := time.Parse("2006-01-02", date)


+ 1
- 1
routers/routes/routes.go View File

@@ -791,7 +791,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef())

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
m.Group("/:username/:reponame", func() {
m.Group("/milestone", func() {


Loading…
Cancel
Save