diff options
author | zeripath <art27@cantab.net> | 2021-02-17 21:32:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 22:32:25 +0100 |
commit | ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb (patch) | |
tree | 669743542988c694b242f92d512bb219eb300635 /modules/indexer/code/bleve.go | |
parent | 7ba158183a34d71b3989512c059a01d35c4c4673 (diff) | |
download | gitea-ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb.tar.gz gitea-ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb.zip |
Reduce calls to git cat-file -s (#14682)
* Reduce calls to git cat-file -s
There are multiple places where there are repeated calls to git cat-file
-s due to the blobs not being created with their size.
Through judicious use of git ls-tree -l and slight adjustments to the
indexer code we can avoid a lot of these calls.
* simplify by always expecting the long format
* Also always set the sized field and tell the indexer the update is sized
Diffstat (limited to 'modules/indexer/code/bleve.go')
-rw-r--r-- | modules/indexer/code/bleve.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/modules/indexer/code/bleve.go b/modules/indexer/code/bleve.go index 826efde4c1..1ebc74c43a 100644 --- a/modules/indexer/code/bleve.go +++ b/modules/indexer/code/bleve.go @@ -179,14 +179,20 @@ func (b *BleveIndexer) addUpdate(commitSha string, update fileUpdate, repo *mode return nil } - stdout, err := git.NewCommand("cat-file", "-s", update.BlobSha). - RunInDir(repo.RepoPath()) - if err != nil { - return err + size := update.Size + + if !update.Sized { + stdout, err := git.NewCommand("cat-file", "-s", update.BlobSha). + RunInDir(repo.RepoPath()) + if err != nil { + return err + } + if size, err = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64); err != nil { + return fmt.Errorf("Misformatted git cat-file output: %v", err) + } } - if size, err := strconv.Atoi(strings.TrimSpace(stdout)); err != nil { - return fmt.Errorf("Misformatted git cat-file output: %v", err) - } else if int64(size) > setting.Indexer.MaxIndexerFileSize { + + if size > setting.Indexer.MaxIndexerFileSize { return b.addDelete(update.Filename, repo, batch) } |