From b925d5309f4bda9290b1eb3d794152489ba80862 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Thu, 26 Oct 2023 18:50:14 +0000 Subject: [PATCH] lfsapi: cache the remote list for each endpoint lookup When we're locking or unlocking multiple times, we may end up looking up the endpoint a few times. This is very cheap if we don't need to invoke Git. However, as written right now, we call Git every time we validate a remote, which is wasteful. To make this more efficient, let's compute the remote list once and cache it to avoid spawning a process. Then, we can use the cached value every time we need to validate a remote. --- lfsapi/endpoint_finder.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lfsapi/endpoint_finder.go b/lfsapi/endpoint_finder.go index 45107edc..7bb1ab80 100644 --- a/lfsapi/endpoint_finder.go +++ b/lfsapi/endpoint_finder.go @@ -41,6 +41,7 @@ type endpointGitFinder struct { aliasMu sync.Mutex aliases map[string]string pushAliases map[string]string + remoteList []string accessMu sync.Mutex urlAccess map[string]creds.AccessMode @@ -61,6 +62,9 @@ func NewEndpointFinder(ctx lfshttp.Context) EndpointFinder { urlAccess: make(map[string]creds.AccessMode), } + remotes, _ := git.RemoteList() + e.remoteList = remotes + e.urlConfig = config.NewURLConfig(e.gitEnv) if v, ok := e.gitEnv.Get("lfs.gitprotocol"); ok { e.gitProtocol = v @@ -187,7 +191,7 @@ func (e *endpointGitFinder) GitRemoteURL(remote string, forpush bool) string { } } - if err := git.ValidateRemote(remote); err == nil { + if err := git.ValidateRemoteFromList(e.remoteList, remote); err == nil { return remote }