diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e834b1ae6..9d379719bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each AppEngine version, listed here to ease deployment and troubleshooting. ## Next Release (replace with git tag when deployed) + * Note: search queries with multiple components are not cached. ## `20250320t094500-all` * Bump runtimeVersion to `2025.03.18`. diff --git a/app/lib/package/search_adapter.dart b/app/lib/package/search_adapter.dart index 2ec8762f7f..53281cc532 100644 --- a/app/lib/package/search_adapter.dart +++ b/app/lib/package/search_adapter.dart @@ -35,8 +35,10 @@ class SearchAdapter { /// /// When the `search` service fails, it falls back to use the name tracker to /// provide package names and perform search in that set. - Future search(SearchForm form, - {required String? rateLimitKey}) async { + Future search( + SearchForm form, { + required String? rateLimitKey, + }) async { final result = (await _searchOrFallback(form, rateLimitKey, true))!; final views = await _getPackageViewsFromHits([...result.packageHits]); return SearchResultPage( diff --git a/app/lib/search/search_client.dart b/app/lib/search/search_client.dart index 36c5bd25bb..56a5b5c0c6 100644 --- a/app/lib/search/search_client.dart +++ b/app/lib/search/search_client.dart @@ -60,6 +60,15 @@ class SearchClient { final serviceUrlParams = Uri(queryParameters: query.toUriQueryParameters()); + // Don't use cache in cases where there is a high chance of cache miss. + // This is a rough heuristic, counting the distinct components in the + // user-provided query. Such components are: + // - free form text (counts as 1 regardless of word count) + // - `sdk:...`, `platform:...` and other tags (counts as 1 each) + if (query.parsedQuery.componentCount > 2) { + skipCache = true; + } + // returns null on timeout (after 5 seconds) Future doCallHttpServiceEndpoint({String? prefix}) async { final httpHostPort = prefix ?? activeConfiguration.searchServicePrefix; diff --git a/pkg/_pub_shared/lib/search/search_form.dart b/pkg/_pub_shared/lib/search/search_form.dart index 7bd52f41b4..2b11d232a7 100644 --- a/pkg/_pub_shared/lib/search/search_form.dart +++ b/pkg/_pub_shared/lib/search/search_form.dart @@ -324,6 +324,13 @@ class ParsedQueryText { !hasAnyDependency && tagsPredicate.isEmpty; + int get componentCount => + (text == null || text!.isEmpty ? 0 : 1) + + (packagePrefix == null ? 0 : 1) + + refDependencies.length + + allDependencies.length + + tagsPredicate._values.length; + @override String toString() { if (hasOnlyFreeText) return text!;