Browse Source

add basic task

tags/v1.21.10.1^2
lewis 4 years ago
parent
commit
bfaa57edbf
5 changed files with 40 additions and 10 deletions
  1. +10
    -4
      models/issue_comment.go
  2. +25
    -0
      modules/cron/tasks_basic.go
  3. +1
    -1
      routers/private/internal.go
  4. +3
    -4
      routers/repo/repo_statistic.go
  5. +1
    -1
      routers/repo/user_data_analysis.go

+ 10
- 4
models/issue_comment.go View File

@@ -7,7 +7,6 @@
package models

import (
"encoding/binary"
"fmt"
"strings"

@@ -1019,10 +1018,17 @@ func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID
}

func GetCommentCountByRepoID(repoID int64) (int64, error) {
sql := fmt.Sprintf("select count(1) from comment where issue_id in (select id from issue where repo_id = %d) and type = %d;", repoID, CommentTypeComment)
res, err := x.Query(sql)
//sql := fmt.Sprintf("select count(1) from comment where issue_id in (select id from issue where repo_id = %d) and type = %d;", repoID, CommentTypeComment)
//res, err := x.Query(sql)
//if err != nil {
// return 0, err
//}
//return int64(binary.BigEndian.Uint64(res[0]["count"])), nil

total, err := x.Where("issue_id in (select id from issue where repo_id = ?) and type = ?", repoID, CommentTypeComment).Count(&Comment{})
if err != nil {
return 0, err
}
return int64(binary.BigEndian.Uint64(res[0]["count"])), nil

return total, nil
}

+ 25
- 0
modules/cron/tasks_basic.go View File

@@ -163,6 +163,28 @@ func registerHandleBlockChainUnSuccessCommits() {
})
}

func registerHandleRepoStatistic() {
RegisterTaskFatal("handle_repo_statistic", &BaseConfig{
Enabled: true,
RunAtStart: false,
Schedule: "@daily",
}, func(ctx context.Context, _ *models.User, _ Config) error {
repo.RepoStatisticAuto()
return nil
})
}

func registerHandleUserStatistic() {
RegisterTaskFatal("handle_user_statistic", &BaseConfig{
Enabled: true,
RunAtStart: false,
Schedule: "@daily",
}, func(ctx context.Context, _ *models.User, _ Config) error {
repo.TimingCountData()
return nil
})
}

func initBasicTasks() {
registerUpdateMirrorTask()
registerRepoHealthCheck()
@@ -177,4 +199,7 @@ func initBasicTasks() {
registerHandleBlockChainUnSuccessRepos()
registerHandleBlockChainMergedPulls()
registerHandleBlockChainUnSuccessCommits()

registerHandleRepoStatistic()
registerHandleUserStatistic()
}

+ 1
- 1
routers/private/internal.go View File

@@ -42,7 +42,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/manager/shutdown", Shutdown)
m.Post("/manager/restart", Restart)
m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues)
m.Post("/cmd/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt)
m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt)
m.Post("/tool/repo_stat", RepoStatisticManually)

}, CheckInternalToken)


+ 3
- 4
routers/repo/repo_statistic.go View File

@@ -1,7 +1,6 @@
package repo

import (
"code.gitea.io/gitea/modules/repository"
"time"

"code.gitea.io/gitea/models"
@@ -63,9 +62,9 @@ func RepoStatisticDaily(date string) {
continue
}

log.Info("%s", repo.OwnerName)
beginTime, endTime := getStatTime(date)
numVisits := repository.AppointProjectView(repo.OwnerName, repo.Name, beginTime, endTime)
//beginTime, endTime := getStatTime(date)
//numVisits := repository.AppointProjectView(repo.OwnerName, repo.Name, beginTime, endTime)
numVisits := 0

repoStat := models.RepoStatistic{
RepoID: repo.ID,


+ 1
- 1
routers/repo/user_data_analysis.go View File

@@ -8,7 +8,7 @@ import (
"code.gitea.io/gitea/modules/log"
)

func TimeingCountData() {
func TimingCountData() {
//query wiki data
log.Info("start to time count data")
wikiMap := make(map[string]int)


Loading…
Cancel
Save