0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-12-13 01:49:47 +01:00
This commit is contained in:
Lunny Xiao 2025-04-29 09:42:24 -07:00
parent 0cfc7f4e4f
commit 35497493c8
3 changed files with 16 additions and 22 deletions

View File

@ -34,28 +34,19 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
return nil, nil, err return nil, nil, err
} }
var revs map[string]*Commit revs, unHitPaths, err := commit.repo.lastCommitCache.getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths)
if commit.repo.LastCommitCache != nil { if err != nil {
var unHitPaths []string return nil, nil, err
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache) }
if len(unHitPaths) > 0 {
revs2, err := GetLastCommitForPaths(ctx, commit.repo.lastCommitCache, c, treePath, unHitPaths)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
if len(unHitPaths) > 0 {
revs2, err := GetLastCommitForPaths(ctx, commit.repo.LastCommitCache, c, treePath, unHitPaths)
if err != nil {
return nil, nil, err
}
for k, v := range revs2 { for k, v := range revs2 {
revs[k] = v revs[k] = v
}
} }
} else {
revs, err = GetLastCommitForPaths(ctx, nil, c, treePath, entryPaths)
}
if err != nil {
return nil, nil, err
} }
commit.repo.gogitStorage.Close() commit.repo.gogitStorage.Close()
@ -154,7 +145,7 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
} }
// GetLastCommitForPaths returns last commit information // GetLastCommitForPaths returns last commit information
func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) { func GetLastCommitForPaths(ctx context.Context, cache *lastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) {
refSha := c.ID().String() refSha := c.ID().String()
// We do a tree traversal with nodes sorted by commit time // We do a tree traversal with nodes sorted by commit time

View File

@ -16,7 +16,7 @@ import (
func (c *lastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error { func (c *lastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error {
commitNodeIndex, _ := c.repo.CommitNodeIndex() commitNodeIndex, _ := c.repo.CommitNodeIndex()
index, err := commitNodeIndex.Get(plumbing.Hash(c.ID.RawValue())) index, err := commitNodeIndex.Get(plumbing.Hash(commit.ID.RawValue()))
if err != nil { if err != nil {
return err return err
} }

View File

@ -28,14 +28,15 @@ const isGogit = true
type Repository struct { type Repository struct {
Path string Path string
tagCache *ObjectCache[*Tag] tagCache *ObjectCache[*Tag]
commitCache map[string]*Commit
gogitRepo *gogit.Repository gogitRepo *gogit.Repository
gogitStorage *filesystem.Storage gogitStorage *filesystem.Storage
gpgSettings *GPGSettings gpgSettings *GPGSettings
Ctx context.Context Ctx context.Context
LastCommitCache *LastCommitCache lastCommitCache *lastCommitCache
objectFormat ObjectFormat objectFormat ObjectFormat
} }
@ -85,6 +86,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
gogitRepo: gogitRepo, gogitRepo: gogitRepo,
gogitStorage: storage, gogitStorage: storage,
tagCache: newObjectCache[*Tag](), tagCache: newObjectCache[*Tag](),
commitCache: make(map[string]*Commit),
Ctx: ctx, Ctx: ctx,
objectFormat: ParseGogitHash(plumbing.ZeroHash).Type(), objectFormat: ParseGogitHash(plumbing.ZeroHash).Type(),
}, nil }, nil
@ -99,8 +101,9 @@ func (repo *Repository) Close() error {
gitealog.Error("Error closing storage: %v", err) gitealog.Error("Error closing storage: %v", err)
} }
repo.gogitStorage = nil repo.gogitStorage = nil
repo.LastCommitCache = nil repo.lastCommitCache = nil
repo.tagCache = nil repo.tagCache = nil
repo.commitCache = nil
return nil return nil
} }