all repos

mugit @ 56ad3f8dd0ac999a121a4f92b7cbdfede58666c8

🐮 git server that your cow will love
3 files changed, 24 insertions(+), 1 deletions(-)
cache diffs
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-21 17:26:40 +0200
Change ID: ykqvzuswytwnnnlxoumzuquntpsrwynv
Parent: 98cffed
M internal/config/config.go

@@ -50,6 +50,7 @@

type CacheConfig struct { HomePage time.Duration `yaml:"home_page"` Readme time.Duration `yaml:"readme"` + Diff time.Duration `yaml:"duration"` } type Config struct {

@@ -156,6 +157,10 @@ }

if c.Cache.Readme == 0 { c.Cache.Readme = 1 * time.Minute + } + + if c.Cache.Diff == 0 { + c.Cache.Diff = 15 * time.Minute } }
M internal/handlers/handlers.go

@@ -9,6 +9,7 @@ "time"

"olexsmir.xyz/mugit/internal/cache" "olexsmir.xyz/mugit/internal/config" + "olexsmir.xyz/mugit/internal/git" "olexsmir.xyz/mugit/internal/humanize" "olexsmir.xyz/mugit/web" )

@@ -19,6 +20,7 @@ t *template.Template

repoListCache cache.Cacher[[]repoList] readmeCache cache.Cacher[template.HTML] + diffCache cache.Cacher[*git.NiceDiff] } func InitRoutes(cfg *config.Config) http.Handler {

@@ -29,6 +31,7 @@ h := handlers{

cfg, tmpls, cache.NewInMemory[[]repoList](cfg.Cache.HomePage), cache.NewInMemory[template.HTML](cfg.Cache.Readme), + cache.NewInMemory[*git.NiceDiff](cfg.Cache.Diff), } mux := http.NewServeMux()
M internal/handlers/repo.go

@@ -288,7 +288,7 @@ h.write404(w, err)

return } - diff, err := repo.Diff() + diff, err := h.getDiff(repo, ref) if err != nil { h.write500(w, err) return

@@ -431,6 +431,21 @@ })

h.repoListCache.Set("repo_list", repos) return repos, errors.Join(errs...) +} + +func (h handlers) getDiff(r *git.Repo, ref string) (*git.NiceDiff, error) { + cacheKey := fmt.Sprintf("%s:%s", r.Name(), ref) + if v, found := h.diffCache.Get(cacheKey); found { + return v, nil + } + + diff, err := r.Diff() + if err != nil { + return nil, err + } + + h.diffCache.Set(cacheKey, diff) + return diff, nil } var markdown = goldmark.New(