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.
This commit is contained in:
Matthias Riße 2025-01-29 14:28:09 +01:00
parent b0a9f56508
commit c438b7f410
2 changed files with 12 additions and 0 deletions

View file

@ -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) {

View file

@ -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)
}