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.
This commit is contained in:
parent
d2cdff0d68
commit
b925d5309f
@ -41,6 +41,7 @@ type endpointGitFinder struct {
|
|||||||
aliasMu sync.Mutex
|
aliasMu sync.Mutex
|
||||||
aliases map[string]string
|
aliases map[string]string
|
||||||
pushAliases map[string]string
|
pushAliases map[string]string
|
||||||
|
remoteList []string
|
||||||
|
|
||||||
accessMu sync.Mutex
|
accessMu sync.Mutex
|
||||||
urlAccess map[string]creds.AccessMode
|
urlAccess map[string]creds.AccessMode
|
||||||
@ -61,6 +62,9 @@ func NewEndpointFinder(ctx lfshttp.Context) EndpointFinder {
|
|||||||
urlAccess: make(map[string]creds.AccessMode),
|
urlAccess: make(map[string]creds.AccessMode),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remotes, _ := git.RemoteList()
|
||||||
|
e.remoteList = remotes
|
||||||
|
|
||||||
e.urlConfig = config.NewURLConfig(e.gitEnv)
|
e.urlConfig = config.NewURLConfig(e.gitEnv)
|
||||||
if v, ok := e.gitEnv.Get("lfs.gitprotocol"); ok {
|
if v, ok := e.gitEnv.Get("lfs.gitprotocol"); ok {
|
||||||
e.gitProtocol = v
|
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
|
return remote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user