Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 4 additions & 2 deletions app/lib/package/search_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchResultPage> search(SearchForm form,
{required String? rateLimitKey}) async {
Future<SearchResultPage> search(
SearchForm form, {
required String? rateLimitKey,
}) async {
final result = (await _searchOrFallback(form, rateLimitKey, true))!;
final views = await _getPackageViewsFromHits([...result.packageHits]);
return SearchResultPage(
Expand Down
9 changes: 9 additions & 0 deletions app/lib/search/search_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<http.Response?> doCallHttpServiceEndpoint({String? prefix}) async {
final httpHostPort = prefix ?? activeConfiguration.searchServicePrefix;
Expand Down
7 changes: 7 additions & 0 deletions pkg/_pub_shared/lib/search/search_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down