From 74d6dd3f64b17d3a6d79f759dd71d8ada32239fe Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Tue, 21 Jul 2026 23:28:25 +0900 Subject: [PATCH] knotmirror/git: create commit-graph after sync This improves total commit count query about 10x. 10s -> 1s from kernel repository Signed-off-by: Seongmin Lee --- knotmirror/git.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/knotmirror/git.go b/knotmirror/git.go index 7a0238d5..4764db99 100644 --- a/knotmirror/git.go +++ b/knotmirror/git.go @@ -4,12 +4,14 @@ import ( "context" "errors" "fmt" + "log" "net/url" "os" "os/exec" "path/filepath" "regexp" "strings" + "time" "github.com/go-git/go-git/v5" gitconfig "github.com/go-git/go-git/v5/config" @@ -77,6 +79,7 @@ func (c *CliGitMirrorManager) clone(ctx context.Context, path, url string) error } return fmt.Errorf("running 'git clone --mirror %s': %w\n%s", url, err, msg) } + writeCommitGraph(ctx, path, 30 * time.Second) return nil } @@ -129,9 +132,18 @@ func (c *CliGitMirrorManager) fetch(ctx context.Context, path, url string) error } } + writeCommitGraph(ctx, path, 3 * time.Second) return nil } +func writeCommitGraph(ctx context.Context, path string, timeout time.Duration) { + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + if err := exec.CommandContext(ctx, "git", "-C", path, "commit-graph", "write", "--reachable", "--split").Run(); err != nil { + log.Println("failed to run commit-graph", err) + } +} + func (c *CliGitMirrorManager) Sync(ctx context.Context, repo *models.Repo) error { path := c.makeRepoPath(repo) url, err := makeRepoRemoteUrl(repo.KnotDomain, repo.RepoIdentifier(), c.knotUseSSL) -- 2.51.2