From e69b23188a0f2bbca0f15b7e9c17678a4b302f05 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 12 Oct 2021 11:00:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=8E=BB=E6=8E=89=E9=87=8D=E5=A4=8D=E7=9A=84=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=89=80=E6=9C=89=E9=A1=B9=E7=9B=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 10 ---------- models/user_follow.go | 10 ++++++---- modules/git/repo.go | 25 +++---------------------- routers/repo/user_data_analysis.go | 6 +++++- 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 9da0694a5..a00aef0c8 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -344,13 +344,3 @@ func subMonth(t1, t2 time.Time) (month int) { month = yearInterval*12 + monthInterval return month } - -func QueryAllRepo() []*Repository { - sess := x.NewSession() - defer sess.Close() - sess.Select("*").Table("repository") - repositoryList := make([]*Repository, 0) - sess.Find(&repositoryList) - - return repositoryList -} diff --git a/models/user_follow.go b/models/user_follow.go index 51997f681..b63535bb9 100644 --- a/models/user_follow.go +++ b/models/user_follow.go @@ -4,12 +4,14 @@ package models +import "code.gitea.io/gitea/modules/timeutil" + // Follow represents relations of user and his/her followers. type Follow struct { - ID int64 `xorm:"pk autoincr"` - UserID int64 `xorm:"UNIQUE(follow)"` - FollowID int64 `xorm:"UNIQUE(follow)"` - CreatedUnix int64 `xorm:"created"` + ID int64 `xorm:"pk autoincr"` + UserID int64 `xorm:"UNIQUE(follow)"` + FollowID int64 `xorm:"UNIQUE(follow)"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` } // IsFollowing returns true if user is following followID. diff --git a/modules/git/repo.go b/modules/git/repo.go index 3de8ea9eb..a2a4d28af 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -52,25 +52,6 @@ func (repo *Repository) GetAllCommitsCount() (int64, error) { return AllCommitsCount(repo.Path) } -func (repo *Repository) ParsePrettyFormatLogToList(logs []byte) (*list.List, error) { - l := list.New() - if len(logs) == 0 { - return l, nil - } - - parts := bytes.Split(logs, []byte{'\n'}) - - for _, commitID := range parts { - commit, err := repo.GetCommit(string(commitID)) - if err != nil { - return nil, err - } - l.PushBack(commit) - } - - return l, nil -} - func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { l := list.New() if len(logs) == 0 { @@ -460,7 +441,7 @@ type Contributor struct { Email string } -func GetContributors(repoPath string) ([]Contributor, error) { +func GetContributors(repoPath string) ([]Contributor, error){ cmd := NewCommand("shortlog", "-sne", "--all") stdout, err := cmd.RunInDir(repoPath) if err != nil { @@ -477,9 +458,9 @@ func GetContributors(repoPath string) ([]Contributor, error) { } number := oneCount[0:strings.Index(oneCount, "\t")] commitCnt, _ := strconv.Atoi(number) - committer := oneCount[strings.Index(oneCount, "\t")+1 : strings.LastIndex(oneCount, " ")] + committer := oneCount[strings.Index(oneCount, "\t")+1:strings.LastIndex(oneCount, " ")] committer = strings.Trim(committer, " ") - email := oneCount[strings.Index(oneCount, "<")+1 : strings.Index(oneCount, ">")] + email := oneCount[strings.Index(oneCount, "<")+1:strings.Index(oneCount, ">")] contributorsInfo[i] = Contributor{ commitCnt, committer, email, } diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 13850af7a..2d9c03e1d 100644 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -18,7 +18,11 @@ func TimeingCountData() { yesterday := currentTimeNow.AddDate(0, 0, -1) - repoList := models.QueryAllRepo() + repoList, err := models.GetAllRepositories() + if err != nil { + log.Error("query repo error.") + return + } log.Info("start to query wiki data") for _, repoRecord := range repoList { wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name)