diff options
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/pagination.go | 6 | ||||
-rw-r--r-- | modules/context/repo.go | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/modules/context/pagination.go b/modules/context/pagination.go index 9a6ad0b5c4..a6638f4086 100644 --- a/modules/context/pagination.go +++ b/modules/context/pagination.go @@ -37,6 +37,12 @@ func (p *Pagination) AddParam(ctx *Context, paramKey string, ctxKey string) { p.urlParams = append(p.urlParams, urlParam) } +// AddParamString adds a string parameter directly +func (p *Pagination) AddParamString(key string, value string) { + urlParam := fmt.Sprintf("%s=%v", url.QueryEscape(key), url.QueryEscape(value)) + p.urlParams = append(p.urlParams, urlParam) +} + // GetParams returns the configured URL params func (p *Pagination) GetParams() template.URL { return template.URL(strings.Join(p.urlParams, "&")) diff --git a/modules/context/repo.go b/modules/context/repo.go index f34b05d1d0..0ef644b522 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -171,6 +171,18 @@ func (r *Repository) GetCommitsCount() (int64, error) { }) } +// GetCommitGraphsCount returns cached commit count for current view +func (r *Repository) GetCommitGraphsCount(hidePRRefs bool, branches []string, files []string) (int64, error) { + cacheKey := fmt.Sprintf("commits-count-%d-graph-%t-%s-%s", r.Repository.ID, hidePRRefs, branches, files) + + return cache.GetInt64(cacheKey, func() (int64, error) { + if len(branches) == 0 { + return git.AllCommitsCount(r.Repository.RepoPath(), hidePRRefs, files...) + } + return git.CommitsCountFiles(r.Repository.RepoPath(), branches, files) + }) +} + // BranchNameSubURL sub-URL for the BranchName field func (r *Repository) BranchNameSubURL() string { switch { |