diff --git a/models/issue_comment.go b/models/issue_comment.go index ab231f156..60d38452c 100755 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -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 } diff --git a/modules/cron/tasks_basic.go b/modules/cron/tasks_basic.go old mode 100644 new mode 100755 index f42710618..26cd16778 --- a/modules/cron/tasks_basic.go +++ b/modules/cron/tasks_basic.go @@ -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() } diff --git a/routers/private/internal.go b/routers/private/internal.go index 3ca1f08ab..b254d48ba 100755 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -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) diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index 1d9748127..ceb410958 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -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, diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go old mode 100644 new mode 100755 index 2d9c03e1d..3260780ac --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -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)