diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-08-21 01:04:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-20 17:04:57 +0000 |
commit | c03baab678ba5b2e9d974aea147e660417f5d3f7 (patch) | |
tree | 2b890d549a150cc1c9f6101218789601f40b960f /modules/git/tree_entry_nogogit.go | |
parent | 8b92eba21f5c5cca277b8101ada0ea7a1fb32ae0 (diff) | |
download | gitea-c03baab678ba5b2e9d974aea147e660417f5d3f7.tar.gz gitea-c03baab678ba5b2e9d974aea147e660417f5d3f7.zip |
Refactor the usage of batch catfile (#31754)
When opening a repository, it will call `ensureValidRepository` and also
`CatFileBatch`. But sometimes these will not be used until repository
closed. So it's a waste of CPU to invoke 3 times git command for every
open repository.
This PR removed all of these from `OpenRepository` but only kept
checking whether the folder exists. When a batch is necessary, the
necessary functions will be invoked.
Diffstat (limited to 'modules/git/tree_entry_nogogit.go')
-rw-r--r-- | modules/git/tree_entry_nogogit.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/modules/git/tree_entry_nogogit.go b/modules/git/tree_entry_nogogit.go index 89244e27ee..1c3bcd197a 100644 --- a/modules/git/tree_entry_nogogit.go +++ b/modules/git/tree_entry_nogogit.go @@ -42,9 +42,13 @@ func (te *TreeEntry) Size() int64 { return te.size } - wr, rd, cancel := te.ptree.repo.CatFileBatchCheck(te.ptree.repo.Ctx) + wr, rd, cancel, err := te.ptree.repo.CatFileBatchCheck(te.ptree.repo.Ctx) + if err != nil { + log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) + return 0 + } defer cancel() - _, err := wr.Write([]byte(te.ID.String() + "\n")) + _, err = wr.Write([]byte(te.ID.String() + "\n")) if err != nil { log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), te.ptree.repo.Path, err) return 0 |