Skip to content

Commit

Permalink
Add extra optimization path for autocompletion of ^foo/* whereas the …
Browse files Browse the repository at this point in the history
…vendor is fully known, refs composer#10320
  • Loading branch information
Seldaek committed Dec 7, 2021
1 parent 2d19631 commit 748448b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Composer/Repository/ComposerRepository.php
Expand Up @@ -571,6 +571,19 @@ public function search($query, $mode = 0, $type = null)
}

if ($this->hasProviders() || $this->lazyProvidersUrl) {
// optimize search for "^foo/bar" where at least "^foo/" is present by loading this directly from the listUrl if present
if (Preg::isMatch('{^\^(?P<query>(?P<vendor>[a-z0-9_.-]+)/[a-z0-9_.-]*)\*?$}i', $query, $match) && $this->listUrl !== null) {
$url = $this->listUrl . '?vendor='.urlencode($match['vendor']).'&filter='.urlencode($match['query'].'*');
$result = $this->httpDownloader->get($url, $this->options)->decodeJson();

$results = array();
foreach ($result['packageNames'] as $name) {
$results[] = array('name' => $name, 'description' => '');
}

return $results;
}

$results = array();
$regex = '{(?:'.implode('|', Preg::split('{\s+}', $query)).')}i';

Expand Down

0 comments on commit 748448b

Please sign in to comment.