mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-21 09:06:46 +09:00
perf(git): speed up activity top authors and subdirectory listings (#39526)
Speeds up two slow git paths. Results match `main` apart from the `log.follow` fix. - Activity top authors skip `--numstat` and an unused `rev-list --count`, they only need names and emails - Subdirectory listings pass only the directory as pathspec, which already matches all its entries - Directory listings pass `--no-follow` to `git log`, a configured `log.follow` disabled parent rewriting and gave wrong last commits | Benchmark | main | PR | Change | |---|--:|--:|--:| | Top authors, gitea, 1 month | 632 ms | 21 ms | -97% | | Top authors, gitea, 1 year | 3216 ms | 68 ms | -98% | | Top authors, tea | 62 ms | 12 ms | -80% | | Listing, git `Documentation/technical` | 189 ms | 91 ms | -52% | | Listing, gitea `options/license` | 329 ms | 208 ms | -37% | | Listing, gitea `templates/repo` | 294 ms | 223 ms | -24% | Tested with unit and sqlite integration tests in default and `gogit` builds on git 2.25 and 2.56, and by comparing listing results and cache writes with `main` on randomized histories and the gitea, tea and git repos. Benchmarks are medians of 8 interleaved macOS runs.
This commit is contained in:
1 parent
2f5cdbd5c1
commit
075ff8f516
5 files changed
+38
-31
No files matched your search
@@ -61,10 +61,28 @@ func (repo *Repository) GetCodeActivityStats(ctx context.Context, fromTime time.
|
||||
} else {
|
||||
gitCmd.AddArguments("--first-parent").AddDynamicArguments(branch)
|
||||
}
|
||||
if err := parseCodeActivityLog(ctx, repo, gitCmd, stats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// GetCodeActivityAuthors returns the authors of non-merge commits in all branches since fromTime, sorted by commit count
|
||||
func GetCodeActivityAuthors(ctx context.Context, repo RepositoryFacade, fromTime time.Time) ([]*CodeActivityAuthor, error) {
|
||||
stats := &CodeActivityStats{}
|
||||
gitCmd := gitcmd.NewCommand("log", "--no-merges", "--pretty=format:---%n%H%n%aN%n%aE%n", "--branches=*").
|
||||
AddOptionFormat("--since=%s", fromTime.Format(time.RFC3339))
|
||||
if err := parseCodeActivityLog(ctx, repo, gitCmd, stats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return stats.Authors, nil
|
||||
}
|
||||
|
||||
func parseCodeActivityLog(ctx context.Context, repo RepositoryFacade, gitCmd *gitcmd.Command, stats *CodeActivityStats) error {
|
||||
stdoutReader, stdoutReaderClose := gitCmd.MakeStdoutPipe()
|
||||
defer stdoutReaderClose()
|
||||
err = gitCmd.
|
||||
err := gitCmd.
|
||||
WithRepo(repo).
|
||||
WithPipelineFunc(func(ctx gitcmd.Context) error {
|
||||
scanner := bufio.NewScanner(stdoutReader)
|
||||
@@ -116,8 +134,8 @@ func (repo *Repository) GetCodeActivityStats(ctx context.Context, fromTime time.
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = scanner.Err(); err != nil {
|
||||
return fmt.Errorf("GetCodeActivityStats scan: %w", err)
|
||||
if err := scanner.Err(); err != nil {
|
||||
return fmt.Errorf("parseCodeActivityLog scan: %w", err)
|
||||
}
|
||||
a := make([]*CodeActivityAuthor, 0, len(authors))
|
||||
for _, v := range authors {
|
||||
@@ -134,8 +152,7 @@ func (repo *Repository) GetCodeActivityStats(ctx context.Context, fromTime time.
|
||||
}).
|
||||
RunWithStderr(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetCodeActivityStats: %w", err)
|
||||
return fmt.Errorf("parseCodeActivityLog: %w", err)
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user