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.
Store the overview's summaries when a push lands
2a8f7cef47240564179a45126863d1ccd8d9d362 · Keenan Nemetz · 10d ago · parent 8dc56e4e
Store the overview's summaries when a push lands The repository overview walked git on every read: `rev-parse` for the tip, `log` for the last five commits, `for-each-ref` for tags, `ls-tree` plus `shortlog` for languages and contributors, and a `cat-file` for the README. All of those describe a ref except the README, and a ref moves only when a push lands, so the push now records them. - Schema v10 adds `repo_languages`, `repo_commits`, `repo_contributors` and `repo_tags`. - `RefreshHead` stores the tip's newest commits and its language breakdown from one `ls-tree -r -l`, and returns whether the tip moved. - `RefreshContributors` stores the top authors; the hook calls it only when the tip changed, never on a metadata or tag push. - `RefreshTags` stores the tag rows beside the release events it already rewrote, and `IndexRepo` now refreshes tags and contributors too, so a rebuild restores everything a push would have written. - The overview reads those rows when the recorded head is the branch tip (`RefCommit` is a loose-ref file read) and falls back to git when it is not, so a missed hook shows the correct page rather than a stale one. If one stored section is empty on a repository with commits, that section alone is re-read from git. - The sidebar asks SQL for five open issues and changes instead of sorting the whole open queue in memory. - The rendered README is cached by repository, commit and ref under a byte budget, so the overview's last git spawn is gone after the first read of a commit. - The language fallback reads one `ls-tree -r -l` instead of `ls-tree` followed by a `cat-file --batch-check`. - `Remove` deletes every derived row for a repository, not only its row. Load harness at concurrency 4: overview goes from 473 to about 740 req/s, p50 from 8 ms to 5 ms, and the server runs no git child process for the warm requests.
forge/index/overview.go +127
| @@ -0,0 +1,127 @@ | |||
| 1 | package index | ||
| 2 | |||
| 3 | // The overview's stored summaries: the default branch's recent commits, the | ||
| 4 | // languages it is mostly made of, its authors, and the repository's tags. | ||
| 5 | // | ||
| 6 | // All four change when a ref moves, so they are written then (see RefreshHead, | ||
| 7 | // RefreshContributors and RefreshTags) and read as rows. A repository page then | ||
| 8 | // has no reason to walk the tree or the history. | ||
| 9 | |||
| 10 | import "github.com/rodent-software/vole/internal/lang" | ||
| 11 | |||
| 12 | type CommitRow struct { | ||
| 13 | SHA string | ||
| 14 | Subject string | ||
| 15 | Author string | ||
| 16 | When int64 | ||
| 17 | } | ||
| 18 | |||
| 19 | type ContributorRow struct { | ||
| 20 | Name string | ||
| 21 | Commits int | ||
| 22 | } | ||
| 23 | |||
| 24 | // TagRow is one entry of refs/tags, peeled to the commit it names. | ||
| 25 | type TagRow struct { | ||
| 26 | Name string | ||
| 27 | OID string | ||
| 28 | Commit string | ||
| 29 | Annotated bool | ||
| 30 | Tagger string | ||
| 31 | When int64 | ||
| 32 | Subject string | ||
| 33 | } | ||
| 34 | |||
| 35 | // RecentCommits returns the default branch's newest commits, newest first. It is | ||
| 36 | // the first page of the history, recorded when the tip was pushed. | ||
| 37 | func (s *Store) RecentCommits(repoID string, n int) ([]CommitRow, error) { | ||
| 38 | q := `SELECT sha, subject, author, when_at FROM repo_commits WHERE repo_id=? ORDER BY pos` | ||
| 39 | args := []any{repoID} | ||
| 40 | if n > 0 { | ||
| 41 | q += ` LIMIT ?` | ||
| 42 | args = append(args, n) | ||
| 43 | } | ||
| 44 | rows, err := s.db.Query(q, args...) | ||
| 45 | if err != nil { | ||
| 46 | return nil, err | ||
| 47 | } | ||
| 48 | defer rows.Close() | ||
| 49 | var out []CommitRow | ||
| 50 | for rows.Next() { | ||
| 51 | var c CommitRow | ||
| 52 | if err := rows.Scan(&c.SHA, &c.Subject, &c.Author, &c.When); err != nil { | ||
| 53 | return nil, err | ||
| 54 | } | ||
| 55 | out = append(out, c) | ||
| 56 | } | ||
| 57 | return out, rows.Err() | ||
| 58 | } | ||
| 59 | |||
| 60 | // Languages returns the default branch's language groups by size, largest first. | ||
| 61 | // The rows include "Other", so a percentage has a total to divide by. | ||
| 62 | func (s *Store) Languages(repoID string) ([]lang.Share, error) { | ||
| 63 | rows, err := s.db.Query(`SELECT name, bytes FROM repo_languages WHERE repo_id=? ORDER BY bytes DESC, name`, repoID) | ||
| 64 | if err != nil { | ||
| 65 | return nil, err | ||
| 66 | } | ||
| 67 | defer rows.Close() | ||
| 68 | var out []lang.Share | ||
| 69 | for rows.Next() { | ||
| 70 | var sh lang.Share | ||
| 71 | if err := rows.Scan(&sh.Name, &sh.Bytes); err != nil { | ||
| 72 | return nil, err | ||
| 73 | } | ||
| 74 | out = append(out, sh) | ||
| 75 | } | ||
| 76 | return out, rows.Err() | ||
| 77 | } | ||
| 78 | |||
| 79 | // Contributors returns the authors of the default branch, most commits first. | ||
| 80 | func (s *Store) Contributors(repoID string, n int) ([]ContributorRow, error) { | ||
| 81 | q := `SELECT name, commits FROM repo_contributors WHERE repo_id=? ORDER BY pos` | ||
| 82 | args := []any{repoID} | ||
| 83 | if n > 0 { | ||
| 84 | q += ` LIMIT ?` | ||
| 85 | args = append(args, n) | ||
| 86 | } | ||
| 87 | rows, err := s.db.Query(q, args...) | ||
| 88 | if err != nil { | ||
| 89 | return nil, err | ||
| 90 | } | ||
| 91 | defer rows.Close() | ||
| 92 | var out []ContributorRow | ||
| 93 | for rows.Next() { | ||
| 94 | var c ContributorRow | ||
| 95 | if err := rows.Scan(&c.Name, &c.Commits); err != nil { | ||
| 96 | return nil, err | ||
| 97 | } | ||
| 98 | out = append(out, c) | ||
| 99 | } | ||
| 100 | return out, rows.Err() | ||
| 101 | } | ||
| 102 | |||
| 103 | // Tags returns the repository's tags, newest first, which is the order the | ||
| 104 | // releases section shows. | ||
| 105 | func (s *Store) Tags(repoID string, n int) ([]TagRow, error) { | ||
| 106 | q := `SELECT name, oid, commit_sha, annotated, tagger, when_at, subject | ||
| 107 | FROM repo_tags WHERE repo_id=? ORDER BY when_at DESC, name` | ||
| 108 | args := []any{repoID} | ||
| 109 | if n > 0 { | ||
| 110 | q += ` LIMIT ?` | ||
| 111 | args = append(args, n) | ||
| 112 | } | ||
| 113 | rows, err := s.db.Query(q, args...) | ||
| 114 | if err != nil { | ||
| 115 | return nil, err | ||
| 116 | } | ||
| 117 | defer rows.Close() | ||
| 118 | var out []TagRow | ||
| 119 | for rows.Next() { | ||
| 120 | var t TagRow | ||
| 121 | if err := rows.Scan(&t.Name, &t.OID, &t.Commit, &t.Annotated, &t.Tagger, &t.When, &t.Subject); err != nil { | ||
| 122 | return nil, err | ||
| 123 | } | ||
| 124 | out = append(out, t) | ||
| 125 | } | ||
| 126 | return out, rows.Err() | ||
| 127 | } | ||