From fd1a61803a66e4747911977b6c8798bcffb5ee4a Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Mon, 10 Feb 2025 18:07:53 -0500 Subject: [PATCH] perf(search) free money, a.k.a. fast fail --- libexec/scoop-search.ps1 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index d94b18660d..ba83785b18 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -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) { @@ -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 } }