forked from TrueCloudLab/distribution
Merge pull request #4022 from Jamstah/catalog-optimisation
Don't make a new buffer for catalog listing
This commit is contained in:
commit
3a44c2e10e
1 changed files with 17 additions and 15 deletions
|
@ -14,12 +14,12 @@ import (
|
||||||
// Returns a list, or partial list, of repositories in the registry.
|
// Returns a list, or partial list, of repositories in the registry.
|
||||||
// Because it's a quite expensive operation, it should only be used when building up
|
// Because it's a quite expensive operation, it should only be used when building up
|
||||||
// an initial set of repositories.
|
// an initial set of repositories.
|
||||||
func (reg *registry) Repositories(ctx context.Context, repos []string, last string) (n int, err error) {
|
func (reg *registry) Repositories(ctx context.Context, repos []string, last string) (int, error) {
|
||||||
var finishedWalk bool
|
filledBuffer := false
|
||||||
var foundRepos []string
|
foundRepos := 0
|
||||||
|
|
||||||
if len(repos) == 0 {
|
if len(repos) == 0 {
|
||||||
return 0, errors.New("no space in slice")
|
return 0, errors.New("Attempted to list 0 repositories")
|
||||||
}
|
}
|
||||||
|
|
||||||
root, err := pathFor(repositoriesRootPathSpec{})
|
root, err := pathFor(repositoriesRootPathSpec{})
|
||||||
|
@ -29,32 +29,34 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri
|
||||||
|
|
||||||
err = reg.blobStore.driver.Walk(ctx, root, func(fileInfo driver.FileInfo) error {
|
err = reg.blobStore.driver.Walk(ctx, root, func(fileInfo driver.FileInfo) error {
|
||||||
err := handleRepository(fileInfo, root, last, func(repoPath string) error {
|
err := handleRepository(fileInfo, root, last, func(repoPath string) error {
|
||||||
foundRepos = append(foundRepos, repoPath)
|
repos[foundRepos] = repoPath
|
||||||
|
foundRepos += 1
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we've filled our array, no need to walk any further
|
// if we've filled our slice, no need to walk any further
|
||||||
if len(foundRepos) == len(repos) {
|
if foundRepos == len(repos) {
|
||||||
finishedWalk = true
|
filledBuffer = true
|
||||||
return driver.ErrSkipDir
|
return driver.ErrSkipDir
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
n = copy(repos, foundRepos)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return foundRepos, err
|
||||||
} else if !finishedWalk {
|
|
||||||
// We didn't fill buffer. No more records are available.
|
|
||||||
return n, io.EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n, err
|
if filledBuffer {
|
||||||
|
// There are potentially more repositories to list
|
||||||
|
return foundRepos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// We didn't fill the buffer, so that's the end of the list of repos
|
||||||
|
return foundRepos, io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enumerate applies ingester to each repository
|
// Enumerate applies ingester to each repository
|
||||||
|
|
Loading…
Reference in a new issue