3 files changed,
24 insertions(+),
1 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-21 17:26:40 +0200
Authored at:
2026-02-21 17:23:49 +0200
Change ID:
ykqvzuswytwnnnlxoumzuquntpsrwynv
Parent:
98cffed
M
internal/config/config.go
路路路 50 50 type CacheConfig struct { 51 51 HomePage time.Duration `yaml:"home_page"` 52 52 Readme time.Duration `yaml:"readme"` 53 + Diff time.Duration `yaml:"duration"` 53 54 } 54 55 55 56 type Config struct { 路路路 156 157 157 158 if c.Cache.Readme == 0 { 158 159 c.Cache.Readme = 1 * time.Minute 160 + } 161 + 162 + if c.Cache.Diff == 0 { 163 + c.Cache.Diff = 15 * time.Minute 159 164 } 160 165 } 161 166
M
internal/handlers/handlers.go
路路路 9 9 10 10 "olexsmir.xyz/mugit/internal/cache" 11 11 "olexsmir.xyz/mugit/internal/config" 12 + "olexsmir.xyz/mugit/internal/git" 12 13 "olexsmir.xyz/mugit/internal/humanize" 13 14 "olexsmir.xyz/mugit/web" 14 15 ) 路路路 19 20 20 21 repoListCache cache.Cacher[[]repoList] 21 22 readmeCache cache.Cacher[template.HTML] 23 + diffCache cache.Cacher[*git.NiceDiff] 22 24 } 23 25 24 26 func InitRoutes(cfg *config.Config) http.Handler { 路路路 29 31 cfg, tmpls, 30 32 cache.NewInMemory[[]repoList](cfg.Cache.HomePage), 31 33 cache.NewInMemory[template.HTML](cfg.Cache.Readme), 34 + cache.NewInMemory[*git.NiceDiff](cfg.Cache.Diff), 32 35 } 33 36 34 37 mux := http.NewServeMux()
M
internal/handlers/repo.go
路路路 288 288 return 289 289 } 290 290 291 - diff, err := repo.Diff() 291 + diff, err := h.getDiff(repo, ref) 292 292 if err != nil { 293 293 h.write500(w, err) 294 294 return 路路路 431 431 432 432 h.repoListCache.Set("repo_list", repos) 433 433 return repos, errors.Join(errs...) 434 +} 435 + 436 +func (h handlers) getDiff(r *git.Repo, ref string) (*git.NiceDiff, error) { 437 + cacheKey := fmt.Sprintf("%s:%s", r.Name(), ref) 438 + if v, found := h.diffCache.Get(cacheKey); found { 439 + return v, nil 440 + } 441 + 442 + diff, err := r.Diff() 443 + if err != nil { 444 + return nil, err 445 + } 446 + 447 + h.diffCache.Set(cacheKey, diff) 448 + return diff, nil 434 449 } 435 450 436 451 var markdown = goldmark.New(