1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-23 18:08:28 +00:00

Performance improvement for last commit cache and show-ref (#15455) (#15701)

Backport #15455

* Improve performance when there are multiple commits in the last commit cache

* read refs directly if we can

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath
2021-05-03 15:51:41 +01:00
committed by GitHub
parent 3ce46a7fbd
commit 4fa2804238
3 changed files with 30 additions and 5 deletions

View File

@@ -7,6 +7,8 @@
package git
import (
"bufio"
"io"
"path"
)
@@ -34,7 +36,7 @@ func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl func() int64,
}
// Get get the last commit information by commit id and entry path
func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
func (c *LastCommitCache) Get(ref, entryPath string, wr *io.PipeWriter, rd *bufio.Reader) (interface{}, error) {
v := c.cache.Get(c.getCacheKey(c.repoPath, ref, entryPath))
if vs, ok := v.(string); ok {
log("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs)
@@ -46,7 +48,10 @@ func (c *LastCommitCache) Get(ref, entryPath string) (interface{}, error) {
if err != nil {
return nil, err
}
commit, err := c.repo.getCommit(id)
if _, err := wr.Write([]byte(vs + "\n")); err != nil {
return nil, err
}
commit, err := c.repo.getCommitFromBatchReader(rd, id)
if err != nil {
return nil, err
}