all repos — elgit @ 8f562b78446b9fb5bfc73a6f41788647a3779189

fork of legit: web frontend for git, written in go

update repository list on timer instead of generating per request

Alan Pearce
commit

8f562b78446b9fb5bfc73a6f41788647a3779189

parent

975625f9d4d26eb56f4428f2921b9e1090a49621

3 files changed, 19 insertions(+), 8 deletions(-)

changed files
M routes/handler.goroutes/handler.go
@@ -13,6 +13,7 @@ "github.com/fsnotify/fsnotify"
"github.com/savsgio/atreugo/v11" "alin.ovh/elgit/config" + "alin.ovh/elgit/data" ) var ErrMethodNotAllowed = fmt.Errorf("that's not possible")
@@ -26,8 +27,9 @@ log.Fatal(err)
} d := deps{ - c, - projects, + c: c, + projects: projects, + repos: &data.Entries{}, } addr := net.JoinHostPort(c.Server.Host, strconv.FormatInt(c.Server.Port, 10))
@@ -60,6 +62,13 @@ err = watcher.Add(plist)
if err != nil { log.Fatal(err) } + + go func() { + d.UpdateRepos() + for range time.Tick(time.Minute) { + d.UpdateRepos() + } + }() go func() { for {
M routes/routes.goroutes/routes.go
@@ -10,6 +10,7 @@ "strconv"
"strings" "alin.ovh/elgit/config" + "alin.ovh/elgit/data" "alin.ovh/elgit/git" "alin.ovh/elgit/templates" "github.com/microcosm-cc/bluemonday"
@@ -21,10 +22,11 @@
type deps struct { c *config.Config projects []string + repos *data.Entries } func (d *deps) Index(rc *atreugo.RequestCtx) error { - repos := d.getAllRepos() + pageData := templates.PageData{ Meta: d.c.Meta,
@@ -32,7 +34,7 @@ }
rc.SetContentType("text/html; charset=utf-8") - return templates.IndexPage(pageData, repos).Render(rc) + return templates.IndexPage(pageData, d.repos).Render(rc) } func (d *deps) RepoIndex(rc *atreugo.RequestCtx) error {
M routes/util.goroutes/util.go
@@ -4,6 +4,7 @@ import (
"bufio" "log" "os" + "path" "path/filepath" "slices" "strings"
@@ -11,7 +12,6 @@
"alin.ovh/elgit/data" "alin.ovh/elgit/git" securejoin "github.com/cyphar/filepath-securejoin" - "github.com/dimfeld/httptreemux/v5" "github.com/savsgio/atreugo/v11" )
@@ -47,7 +47,7 @@
func (d *deps) GetCleanPath(name string) (string, error) { return securejoin.SecureJoin( filepath.Join(d.c.Repo.Root, "repositories"), - httptreemux.Clean(name)+".git", + path.Clean(name)+".git", ) }
@@ -71,7 +71,7 @@
return projects, nil } -func (d *deps) getAllRepos() *data.Entries { +func (d *deps) UpdateRepos() { entries := &data.Entries{ Children: []*data.Entry{}, Map: map[string]*data.Entry{},
@@ -111,7 +111,7 @@ }
entries.Sort() - return entries + d.repos = entries } func setContentDisposition(rc *atreugo.RequestCtx, name string) {