vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
Record the default branch summary when a push lands
8dc56e4e258dd56e2c20776f80d61dbed4993f31 · Keenan Nemetz · 10d ago · parent 20442b59
Record the default branch summary when a push lands The landing card showed the default branch tip and the language it is mostly made of by running `symbolic-ref`, `rev-parse`, `log -1` and `ls-tree -r` per repository on every home page read. Those facts change only when a push moves the branch, so the push now records them. - `repos` carries head_sha, head_subject, head_author, head_when, language and lang_class, and `Index.Entry` returns them with the rest of the row. - `Store.RefreshHead` recomputes the summary and skips the tree walk when the recorded tip is still the branch tip, so a metadata or tag push costs one rev-parse. It runs from post-receive, from the rebuild, and after the default branch changes in settings. - The language mapping moved to `internal/lang`, shared by the web pages and the summary; `fileClass` and `languageFor` are now one table. - The home cards read the head, language, counts, ACL and newest event time from the index. The home page starts no git process at all; the all-git card builder stays as the fallback for a Web without an index. Load harness at concurrency 4 with three repositories: home goes from 243 to 749 req/s, p50 from 16 ms to 5 ms, and the server runs no git child process for those requests.
forge/index/head_test.go +94
| @@ -0,0 +1,94 @@ | |||
| 1 | package index | ||
| 2 | |||
| 3 | // The head summary is what the landing card shows: the default branch tip and | ||
| 4 | // the language it is mostly made of. It is written when a push lands and when a | ||
| 5 | // rebuild runs, so a page read does not start git. | ||
| 6 | |||
| 7 | import ( | ||
| 8 | "testing" | ||
| 9 | |||
| 10 | "github.com/rodent-software/vole/core/git" | ||
| 11 | ) | ||
| 12 | |||
| 13 | func seedHead(t *testing.T, g *git.Repo, files map[string][]byte) string { | ||
| 14 | t.Helper() | ||
| 15 | commit, err := git.CommitFiles(g, "refs/heads/main", func(f map[string][]byte) error { | ||
| 16 | for path, body := range files { | ||
| 17 | f[path] = body | ||
| 18 | } | ||
| 19 | return nil | ||
| 20 | }, "the first commit", "keenan") | ||
| 21 | if err != nil { | ||
| 22 | t.Fatal(err) | ||
| 23 | } | ||
| 24 | return commit | ||
| 25 | } | ||
| 26 | |||
| 27 | func TestRefreshHeadRecordsTheDefaultBranch(t *testing.T) { | ||
| 28 | t.Parallel() | ||
| 29 | s, m, g := incrementalRepo(t) | ||
| 30 | m.DefaultBranch = "main" | ||
| 31 | commit := seedHead(t, g, map[string][]byte{ | ||
| 32 | "main.go": []byte("package main\n"), | ||
| 33 | "README.md": []byte("readme\n"), | ||
| 34 | }) | ||
| 35 | if err := s.RefreshHead(m); err != nil { | ||
| 36 | t.Fatal(err) | ||
| 37 | } | ||
| 38 | e, err := s.Get("demo") | ||
| 39 | if err != nil { | ||
| 40 | t.Fatal(err) | ||
| 41 | } | ||
| 42 | if e.HeadSHA != commit || e.HeadSubject != "the first commit" || e.HeadAuthor != "keenan" { | ||
| 43 | t.Fatalf("head summary = %+v, want %s / the first commit / keenan", e, commit) | ||
| 44 | } | ||
| 45 | if e.HeadWhen == 0 { | ||
| 46 | t.Fatalf("head summary has no time: %+v", e) | ||
| 47 | } | ||
| 48 | if e.Language != "Go" || e.LangClass != "lang-go" { | ||
| 49 | t.Fatalf("language = %q (%q), want Go (lang-go)", e.Language, e.LangClass) | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | func TestRefreshHeadClearsADeletedBranch(t *testing.T) { | ||
| 54 | t.Parallel() | ||
| 55 | s, m, g := incrementalRepo(t) | ||
| 56 | m.DefaultBranch = "main" | ||
| 57 | seedHead(t, g, map[string][]byte{"main.go": []byte("package main\n")}) | ||
| 58 | if err := s.RefreshHead(m); err != nil { | ||
| 59 | t.Fatal(err) | ||
| 60 | } | ||
| 61 | if err := g.DeleteRef("refs/heads/main"); err != nil { | ||
| 62 | t.Fatal(err) | ||
| 63 | } | ||
| 64 | if err := s.RefreshHead(m); err != nil { | ||
| 65 | t.Fatal(err) | ||
| 66 | } | ||
| 67 | e, err := s.Get("demo") | ||
| 68 | if err != nil { | ||
| 69 | t.Fatal(err) | ||
| 70 | } | ||
| 71 | if e.HeadSHA != "" || e.Language != "" || e.LangClass != "" { | ||
| 72 | t.Fatalf("deleted branch left a head summary: %+v", e) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | func TestIndexRepoRestoresTheHeadSummary(t *testing.T) { | ||
| 77 | t.Parallel() | ||
| 78 | s, m, g := incrementalRepo(t) | ||
| 79 | m.DefaultBranch = "main" | ||
| 80 | commit := seedHead(t, g, map[string][]byte{"main.go": []byte("package main\n")}) | ||
| 81 | if _, err := s.db.Exec(`UPDATE repos SET head_sha='' WHERE id=?`, m.ID); err != nil { | ||
| 82 | t.Fatal(err) | ||
| 83 | } | ||
| 84 | if err := s.IndexRepo(m); err != nil { | ||
| 85 | t.Fatal(err) | ||
| 86 | } | ||
| 87 | e, err := s.Get("demo") | ||
| 88 | if err != nil { | ||
| 89 | t.Fatal(err) | ||
| 90 | } | ||
| 91 | if e.HeadSHA != commit || e.Language != "Go" { | ||
| 92 | t.Fatalf("rebuilt head summary = %+v", e) | ||
| 93 | } | ||
| 94 | } | ||