From c438b7f4105f7cd23b867ce060d550601c2cd907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Ri=C3=9Fe?= Date: Wed, 29 Jan 2025 14:28:09 +0100 Subject: [PATCH] Pre-populate the git-annex UUID cache at startup This eliminates the wait time for the first p2phttp connection since server startup at the cost of adding that time to the startup itself. --- modules/annex/annex.go | 9 +++++++++ routers/init.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/modules/annex/annex.go b/modules/annex/annex.go index 7b499fe3f1..a94321f359 100644 --- a/modules/annex/annex.go +++ b/modules/annex/annex.go @@ -20,6 +20,7 @@ import ( "strings" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) @@ -100,6 +101,14 @@ var ( repoPath2uuidCache = make(map[string]string) ) +func Init() error { + if !setting.Annex.Enabled { + return nil + } + log.Info("Populating the git-annex UUID cache with existing repositories") + return updateUUID2RepoPathCache() +} + func updateUUID2RepoPathCache() error { return filepath.WalkDir(setting.RepoRootPath, func(path string, d fs.DirEntry, err error) error { if err == nil && repoConfigFileRe.MatchString(path) { diff --git a/routers/init.go b/routers/init.go index 821a0ef38c..d881edd030 100644 --- a/routers/init.go +++ b/routers/init.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" authmodel "code.gitea.io/gitea/models/auth" + "code.gitea.io/gitea/modules/annex" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/eventsource" "code.gitea.io/gitea/modules/git" @@ -167,6 +168,8 @@ func InitWebInstalled(ctx context.Context) { actions_service.Init() + mustInit(annex.Init) + // Finally start up the cron cron.NewContext(ctx) }