Skip to content

Commit

Permalink
perf(search) free money, a.k.a. fast fail
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Feb 10, 2025
1 parent ac6f1ba commit fd1a618
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions libexec/scoop-search.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function search_bucket_legacy($bucket, $query) {
$apps = Get-ChildItem (Find-BucketDirectory $bucket) -Filter '*.json' -Recurse

$apps | ForEach-Object {
$manifest = [System.IO.File]::ReadAllText($_.FullName) | ConvertFrom-Json -ErrorAction Continue
$content = [System.IO.File]::ReadAllText($_.FullName)
if ($content -notmatch $query) { return }
$manifest = ConvertFrom-Json $content -ErrorAction Continue
$name = $_.BaseName

if ($name -match $query) {
Expand Down Expand Up @@ -176,14 +178,9 @@ if (get_config USE_SQLITE_CACHE) {
abort "Invalid regular expression: $($_.Exception.InnerException.Message)"
}

$jsonTextAvailable = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { [System.IO.Path]::GetFileNameWithoutExtension($_.Location) -eq 'System.Text.Json' }

Get-LocalBucket | ForEach-Object {
if ($jsonTextAvailable) {
search_bucket $_ $query
} else {
search_bucket_legacy $_ $query
}
search_bucket_legacy $_ $query
}
}

Expand Down

0 comments on commit fd1a618

Please sign in to comment.