Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up listdir #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions pypiisms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,22 @@ func handlePypiFileNames(key string) string {
func handlePypiListDir(fetcher FileFetcher, path string) ([]ListDirEntry, error) {
prefix := strings.TrimPrefix(path, "/") // remove initial /
prefix = strings.TrimSuffix(prefix, "/") // and last one
prefix = strings.Replace(prefix, "-", "_", -1)


if len(prefix) < 1 {
return nil, fmt.Errorf("expected a directory to list")
}

// case-insensitive search, search for X* + x*
firstLetter := prefix[0:1]
lowerFiles, err := fetcher.ListDir(strings.ToLower(firstLetter))
if err != nil {
return lowerFiles, err
}
upperFiles, err := fetcher.ListDir(strings.ToUpper(firstLetter))
files, err := fetcher.ListDir(prefix)
if err != nil {
return upperFiles, err
return files, err
}

// now merge both and filter by normalized prefix comparison.
allFiles := append(lowerFiles, upperFiles...)
// now filter by normalized prefix comparison.
normalizedPrefix := normalizeFileName(prefix)
var results []ListDirEntry
for _, entry := range allFiles {
for _, entry := range files {
fileName := normalizeFileName(entry.Name)
if strings.HasPrefix(fileName, normalizedPrefix) {
results = append(results, entry)
Expand Down