From c6311db603cea90a226386da94f3c8c2d1efb2fb Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Mon, 11 Oct 2021 14:25:05 +0800 Subject: [PATCH 1/7] add config sample --- custom/conf/app.ini.sample | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index b444dd008..9fd00a763 100755 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -385,6 +385,17 @@ CONN_MAX_LIFETIME = 3s ; Database maximum number of open connections, default is 0 meaning no maximum MAX_OPEN_CONNS = 0 +[database_statistic] +DB_TYPE = postgres +HOST = 127.0.0.1:5432 +NAME = statistic +USER = +PASSWD = +SCHEMA = +SSL_MODE = disable +CHARSET = utf8 +PATH = + [indexer] ; Issue indexer type, currently support: bleve, db or elasticsearch, default is bleve ISSUE_INDEXER_TYPE = bleve From 9f80819e320b93ea50903dd138babac29e437c61 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 12 Oct 2021 10:20:32 +0800 Subject: [PATCH 2/7] add repo statistic --- models/models.go | 2 +- models/repo_statistic.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 models/repo_statistic.go diff --git a/models/models.go b/models/models.go index 3927dfbf0..412148235 100755 --- a/models/models.go +++ b/models/models.go @@ -136,7 +136,7 @@ func init() { ) tablesStatistic = append(tablesStatistic, - new(FileChunk), + new(RepoStatistic), new(UserBusinessAnalysis), ) diff --git a/models/repo_statistic.go b/models/repo_statistic.go new file mode 100755 index 000000000..a95340225 --- /dev/null +++ b/models/repo_statistic.go @@ -0,0 +1,37 @@ +package models + +import ( + "time" + + "code.gitea.io/gitea/modules/timeutil" +) + +// RepoStatistic statistic info of all repository +type RepoStatistic struct { + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"unique(s) NOT NULL"` + Date time.Time `xorm:"unique(s) NOT NULL"` + NumWatches int64 `xorm:"NOT NULL DEFAULT 0"` + NumStars int64 `xorm:"NOT NULL DEFAULT 0"` + NumForks int64 `xorm:"NOT NULL DEFAULT 0"` + NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"` + NumComments int64 `xorm:"NOT NULL DEFAULT 0"` + NumViews int64 `xorm:"NOT NULL DEFAULT 0"` + NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"` + NumVersions int64 `xorm:"NOT NULL DEFAULT 0"` + //develop months + NumDevMonths int64 `xorm:"NOT NULL DEFAULT 0"` + RepoSize int64 `xorm:"NOT NULL DEFAULT 0"` + DatasetSize int64 `xorm:"NOT NULL DEFAULT 0"` + NumModels int64 `xorm:"NOT NULL DEFAULT 0"` + NumWikiViews int64 `xorm:"NOT NULL DEFAULT 0"` + NumCommits int64 `xorm:"NOT NULL DEFAULT 0"` + NumIssues int64 `xorm:"NOT NULL DEFAULT 0"` + NumPulls int64 `xorm:"NOT NULL DEFAULT 0"` + IssueFixedRate float32 `xorm:"NOT NULL"` + NumContributor int64 `xorm:"NOT NULL DEFAULT 0"` + NumKeyContributor int64 `xorm:"NOT NULL DEFAULT 0"` + + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` +} From e64b28f9e9fc0e093cb24f9ba39cd9b91422e69b Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 12 Oct 2021 15:45:20 +0800 Subject: [PATCH 3/7] delete all daily --- models/repo_statistic.go | 22 +++++++++++++++++++ routers/repo/repo_statistic.go | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 routers/repo/repo_statistic.go diff --git a/models/repo_statistic.go b/models/repo_statistic.go index a95340225..5fddb769e 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "time" "code.gitea.io/gitea/modules/timeutil" @@ -35,3 +36,24 @@ type RepoStatistic struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } + + +func DeleteRepoStatDaily(date time.Time) error { + sess := xStatistic.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return fmt.Errorf("Begin: %v", err) + } + + if _, err := sess.Where("date = ?", date).Delete(&RepoStatistic{}); err != nil { + return fmt.Errorf("Delete: %v", err) + } + + if err := sess.Commit(); err != nil { + sess.Close() + return fmt.Errorf("Commit: %v", err) + } + + sess.Close() + return nil +} diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go new file mode 100755 index 000000000..85184db21 --- /dev/null +++ b/routers/repo/repo_statistic.go @@ -0,0 +1,39 @@ +package repo + +import ( + "time" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/log" +) + +//auto daily or manually +func RepoStatisticDaily() { + //delete all yesterday + log.Info("", time.Now()) + yesterday := time.Now().AddDate(0, 0, -1) + log.Info("", yesterday) + if err := models.DeleteRepoStatDaily(yesterday); err != nil { + log.Error("DeleteRepoStatDaily failed: %v", err.Error()) + return + } + + repos, err := models.GetAllRepositories() + if err != nil { + log.Error("GetAllRepositories failed: %v", err.Error()) + return + } + + for _, repo := range repos { + log.Info("start statistic: %s", repo.Name) + repoStat, err := models.GetRepoKPIStats(repo) + if err != nil { + log.Error("GetRepoKPIStats failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } + log.Info("", repoStat.DevelopAge) + log.Info("finish statistic: %s", repo.Name) + } + +} From c6bedceb5002e0d22ea9361772eb20829b548767 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 14 Oct 2021 16:43:45 +0800 Subject: [PATCH 4/7] 1 --- models/repo_statistic.go | 4 ++++ routers/repo/repo_statistic.go | 35 ++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/models/repo_statistic.go b/models/repo_statistic.go index 5fddb769e..afe32bcb9 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -57,3 +57,7 @@ func DeleteRepoStatDaily(date time.Time) error { sess.Close() return nil } + +func InsertRepoStat(repoStat *RepoStatistic) (int64, error) { + return xStatistic.Insert(repoStat) +} diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index 85184db21..ceb206218 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -26,13 +26,44 @@ func RepoStatisticDaily() { for _, repo := range repos { log.Info("start statistic: %s", repo.Name) - repoStat, err := models.GetRepoKPIStats(repo) + repoGitStat, err := models.GetRepoKPIStats(repo) if err != nil { log.Error("GetRepoKPIStats failed: %s", repo.Name) log.Error("failed statistic: %s", repo.Name) continue } - log.Info("", repoStat.DevelopAge) + log.Info("", repoGitStat.DevelopAge) + + repoStat := models.RepoStatistic{ + RepoID: repo.ID, + Date:yesterday, + NumWatches:int64(repo.NumWatches), + NumStars:int64(repo.NumStars), + NumDownloads:repo.CloneCnt, + NumComments:0, + NumViews:0, + NumClosedIssues:0, + NumVersions:0, + NumDevMonths:repoGitStat.DevelopAge, + RepoSize:0, + DatasetSize:0, + NumModels:0, + NumWikiViews:0, + NumCommits:0, + NumIssues:0, + NumPulls:0, + IssueFixedRate:0, + NumContributor:repoGitStat.Contributors, + NumKeyContributor:repoGitStat.KeyContributors, + + } + + if _, err = models.InsertRepoStat(&repoStat); err != nil { + log.Error("InsertRepoStat failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } + log.Info("finish statistic: %s", repo.Name) } From 5863feaab088752418b1333c756c27a539bdd7db Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 14 Oct 2021 18:10:44 +0800 Subject: [PATCH 5/7] stat --- models/attachment.go | 9 +++++++ models/release.go | 0 models/repo_statistic.go | 3 +-- routers/repo/repo_statistic.go | 47 ++++++++++++++++++++++++++-------- 4 files changed, 47 insertions(+), 12 deletions(-) mode change 100644 => 100755 models/release.go diff --git a/models/attachment.go b/models/attachment.go index 418d7c881..684a38b21 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -464,3 +464,12 @@ func CanDelAttachment(isSigned bool, user *User, attach *Attachment) bool { } return false } + +func GetAttachmentSizeByDatasetID(datasetID int64) (int64, error) { + total, err := x.Where("dataset_id = ?", datasetID).SumInt(&Attachment{}, "size") + if err != nil { + return 0, err + } + + return total, nil +} diff --git a/models/release.go b/models/release.go old mode 100644 new mode 100755 diff --git a/models/repo_statistic.go b/models/repo_statistic.go index afe32bcb9..6077f8c21 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -17,7 +17,7 @@ type RepoStatistic struct { NumForks int64 `xorm:"NOT NULL DEFAULT 0"` NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"` NumComments int64 `xorm:"NOT NULL DEFAULT 0"` - NumViews int64 `xorm:"NOT NULL DEFAULT 0"` + NumVisits int64 `xorm:"NOT NULL DEFAULT 0"` NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"` NumVersions int64 `xorm:"NOT NULL DEFAULT 0"` //develop months @@ -37,7 +37,6 @@ type RepoStatistic struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } - func DeleteRepoStatDaily(date time.Time) error { sess := xStatistic.NewSession() defer sess.Close() diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index ceb206218..982ec1c27 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -32,7 +32,25 @@ func RepoStatisticDaily() { log.Error("failed statistic: %s", repo.Name) continue } - log.Info("", repoGitStat.DevelopAge) + + var issueFixedRate float32 + if repo.NumIssues != 0 { + issueFixedRate = float32(repo.NumClosedIssues) / float32(repo.NumIssues) + } + + numVersions, err := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{}) + if err != nil { + log.Error("GetReleaseCountByRepoID failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } + + datasetSize, err := getDatasetSize(repo) + if err != nil { + log.Error("getDatasetSize failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } repoStat := models.RepoStatistic{ RepoID: repo.ID, @@ -41,18 +59,18 @@ func RepoStatisticDaily() { NumStars:int64(repo.NumStars), NumDownloads:repo.CloneCnt, NumComments:0, - NumViews:0, - NumClosedIssues:0, - NumVersions:0, + NumVisits:0, + NumClosedIssues:int64(repo.NumClosedIssues), + NumVersions:numVersions, NumDevMonths:repoGitStat.DevelopAge, - RepoSize:0, - DatasetSize:0, + RepoSize:repo.Size, + DatasetSize:datasetSize, NumModels:0, NumWikiViews:0, - NumCommits:0, - NumIssues:0, - NumPulls:0, - IssueFixedRate:0, + NumCommits:repo.NumCommit, + NumIssues:int64(repo.NumIssues), + NumPulls:int64(repo.NumPulls), + IssueFixedRate:issueFixedRate, NumContributor:repoGitStat.Contributors, NumKeyContributor:repoGitStat.KeyContributors, @@ -68,3 +86,12 @@ func RepoStatisticDaily() { } } + +func getDatasetSize(repo *models.Repository) (int64, error) { + dataset, err := models.GetDatasetByRepo(repo) + if err != nil { + return 0, err + } + + return models.GetAttachmentSizeByDatasetID(dataset.ID) +} From 6d023d02669f45dd1b7b83f66c3d31fe773b1701 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 15 Oct 2021 12:27:31 +0800 Subject: [PATCH 6/7] repo_stat --- models/issue_comment.go | 10 ++++ models/repo_statistic.go | 28 +++++------ routers/private/internal.go | 1 + routers/private/{cmd.go => tool.go} | 9 +++- routers/repo/repo_statistic.go | 78 +++++++++++++++++++---------- 5 files changed, 84 insertions(+), 42 deletions(-) mode change 100644 => 100755 models/issue_comment.go rename routers/private/{cmd.go => tool.go} (87%) diff --git a/models/issue_comment.go b/models/issue_comment.go old mode 100644 new mode 100755 index f7017435d..ab231f156 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -7,6 +7,7 @@ package models import ( + "encoding/binary" "fmt" "strings" @@ -1016,3 +1017,12 @@ func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID }) return err } + +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) + if err != nil { + return 0, err + } + return int64(binary.BigEndian.Uint64(res[0]["count"])), nil +} diff --git a/models/repo_statistic.go b/models/repo_statistic.go index 6077f8c21..b987f4f46 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -1,25 +1,23 @@ package models import ( - "fmt" - "time" - "code.gitea.io/gitea/modules/timeutil" + "fmt" ) // RepoStatistic statistic info of all repository type RepoStatistic struct { - ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"unique(s) NOT NULL"` - Date time.Time `xorm:"unique(s) NOT NULL"` - NumWatches int64 `xorm:"NOT NULL DEFAULT 0"` - NumStars int64 `xorm:"NOT NULL DEFAULT 0"` - NumForks int64 `xorm:"NOT NULL DEFAULT 0"` - NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"` - NumComments int64 `xorm:"NOT NULL DEFAULT 0"` - NumVisits int64 `xorm:"NOT NULL DEFAULT 0"` - NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"` - NumVersions int64 `xorm:"NOT NULL DEFAULT 0"` + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"unique(s) NOT NULL"` + Date string `xorm:"unique(s) NOT NULL"` + NumWatches int64 `xorm:"NOT NULL DEFAULT 0"` + NumStars int64 `xorm:"NOT NULL DEFAULT 0"` + NumForks int64 `xorm:"NOT NULL DEFAULT 0"` + NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"` + NumComments int64 `xorm:"NOT NULL DEFAULT 0"` + NumVisits int64 `xorm:"NOT NULL DEFAULT 0"` + NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"` + NumVersions int64 `xorm:"NOT NULL DEFAULT 0"` //develop months NumDevMonths int64 `xorm:"NOT NULL DEFAULT 0"` RepoSize int64 `xorm:"NOT NULL DEFAULT 0"` @@ -37,7 +35,7 @@ type RepoStatistic struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } -func DeleteRepoStatDaily(date time.Time) error { +func DeleteRepoStatDaily(date string) error { sess := xStatistic.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { diff --git a/routers/private/internal.go b/routers/private/internal.go index 9d5f7b31c..3ca1f08ab 100755 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -43,6 +43,7 @@ func RegisterRoutes(m *macaron.Macaron) { 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/repo_stat", RepoStatisticManually) }, CheckInternalToken) } diff --git a/routers/private/cmd.go b/routers/private/tool.go similarity index 87% rename from routers/private/cmd.go rename to routers/private/tool.go index 3c44ae697..a7a7bee9d 100755 --- a/routers/private/cmd.go +++ b/routers/private/tool.go @@ -5,11 +5,13 @@ package private import ( - "gitea.com/macaron/macaron" "net/http" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/routers/repo" + + "gitea.com/macaron/macaron" ) func UpdateAllRepoCommitCnt(ctx *macaron.Context) { @@ -35,3 +37,8 @@ func UpdateAllRepoCommitCnt(ctx *macaron.Context) { "error_msg": "", }) } + +func RepoStatisticManually(ctx *macaron.Context) { + date := ctx.Query("date") + repo.RepoStatisticDaily(date) +} diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index 982ec1c27..1d9748127 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -1,6 +1,7 @@ package repo import ( + "code.gitea.io/gitea/modules/repository" "time" "code.gitea.io/gitea/models" @@ -8,12 +9,15 @@ import ( ) //auto daily or manually -func RepoStatisticDaily() { - //delete all yesterday +func RepoStatisticAuto() { log.Info("", time.Now()) - yesterday := time.Now().AddDate(0, 0, -1) - log.Info("", yesterday) - if err := models.DeleteRepoStatDaily(yesterday); err != nil { + yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02") + RepoStatisticDaily(yesterday) +} + +func RepoStatisticDaily(date string) { + log.Info("%s", date) + if err := models.DeleteRepoStatDaily(date); err != nil { log.Error("DeleteRepoStatDaily failed: %v", err.Error()) return } @@ -52,28 +56,38 @@ func RepoStatisticDaily() { continue } - repoStat := models.RepoStatistic{ - RepoID: repo.ID, - Date:yesterday, - NumWatches:int64(repo.NumWatches), - NumStars:int64(repo.NumStars), - NumDownloads:repo.CloneCnt, - NumComments:0, - NumVisits:0, - NumClosedIssues:int64(repo.NumClosedIssues), - NumVersions:numVersions, - NumDevMonths:repoGitStat.DevelopAge, - RepoSize:repo.Size, - DatasetSize:datasetSize, - NumModels:0, - NumWikiViews:0, - NumCommits:repo.NumCommit, - NumIssues:int64(repo.NumIssues), - NumPulls:int64(repo.NumPulls), - IssueFixedRate:issueFixedRate, - NumContributor:repoGitStat.Contributors, - NumKeyContributor:repoGitStat.KeyContributors, + numComments, err := models.GetCommentCountByRepoID(repo.ID) + if err != nil { + log.Error("GetCommentCountByRepoID failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } + + log.Info("%s", repo.OwnerName) + beginTime, endTime := getStatTime(date) + numVisits := repository.AppointProjectView(repo.OwnerName, repo.Name, beginTime, endTime) + repoStat := models.RepoStatistic{ + RepoID: repo.ID, + Date: date, + NumWatches: int64(repo.NumWatches), + NumStars: int64(repo.NumStars), + NumDownloads: repo.CloneCnt, + NumComments: numComments, + NumVisits: int64(numVisits), + NumClosedIssues: int64(repo.NumClosedIssues), + NumVersions: numVersions, + NumDevMonths: repoGitStat.DevelopAge, + RepoSize: repo.Size, + DatasetSize: datasetSize, + NumModels: 0, + NumWikiViews: repoGitStat.WikiPages, + NumCommits: repo.NumCommit, + NumIssues: int64(repo.NumIssues), + NumPulls: int64(repo.NumPulls), + IssueFixedRate: issueFixedRate, + NumContributor: repoGitStat.Contributors, + NumKeyContributor: repoGitStat.KeyContributors, } if _, err = models.InsertRepoStat(&repoStat); err != nil { @@ -95,3 +109,15 @@ func getDatasetSize(repo *models.Repository) (int64, error) { return models.GetAttachmentSizeByDatasetID(dataset.ID) } + +func getStatTime(timeStr string) (string, string) { + t, _ := time.Parse("2006-01-02", timeStr) + timeNumber := t.Unix() + beginTimeNumber := timeNumber - 8*60*60 + endTimeNumber := timeNumber + 16*60*60 + beginTime := time.Unix(beginTimeNumber, 0).Format(time.RFC3339) + endTime := time.Unix(endTimeNumber, 0).Format(time.RFC3339) + log.Info("%s, %s", beginTime, endTime) + + return beginTime, endTime +} From 5ecc2eb580007fc90c5fc1573b0897dbc1623261 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 15 Oct 2021 17:49:40 +0800 Subject: [PATCH 7/7] add basic task --- models/issue_comment.go | 14 ++++++++++---- modules/cron/tasks_basic.go | 25 +++++++++++++++++++++++++ routers/private/internal.go | 2 +- routers/repo/repo_statistic.go | 7 +++---- routers/repo/user_data_analysis.go | 2 +- 5 files changed, 40 insertions(+), 10 deletions(-) mode change 100644 => 100755 modules/cron/tasks_basic.go mode change 100644 => 100755 routers/repo/user_data_analysis.go 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)