Run git gc for repositories (#90)

This commit is contained in:
Thomas Miceli
2023-09-04 11:11:54 +02:00
committed by GitHub
parent a7b346d8df
commit ffafde2b3e
4 changed files with 68 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import (
var (
syncReposFromFS = false
syncReposFromDB = false
gitGcRepos = false
)
func adminIndex(ctx echo.Context) error {
@ -51,6 +52,7 @@ func adminIndex(ctx echo.Context) error {
setData(ctx, "syncReposFromFS", syncReposFromFS)
setData(ctx, "syncReposFromDB", syncReposFromDB)
setData(ctx, "gitGcRepos", gitGcRepos)
return html(ctx, "admin_index.html")
}
@ -185,6 +187,23 @@ func adminSyncReposFromDB(ctx echo.Context) error {
return redirect(ctx, "/admin-panel")
}
func adminGcRepos(ctx echo.Context) error {
addFlash(ctx, "Garbage collecting repositories...", "success")
go func() {
if gitGcRepos {
return
}
gitGcRepos = true
if err := git.GcRepos(); err != nil {
log.Error().Err(err).Msg("Error garbage collecting repositories")
gitGcRepos = false
return
}
gitGcRepos = false
}()
return redirect(ctx, "/admin-panel")
}
func adminConfig(ctx echo.Context) error {
setData(ctx, "title", "Configuration")
setData(ctx, "htmlTitle", "Configuration - Admin panel")

View File

@ -204,6 +204,7 @@ func Start() {
g2.POST("/gists/:gist/delete", adminGistDelete)
g2.POST("/sync-fs", adminSyncReposFromFS)
g2.POST("/sync-db", adminSyncReposFromDB)
g2.POST("/gc-repos", adminGcRepos)
g2.GET("/configuration", adminConfig)
g2.PUT("/set-config", adminSetConfig)
}