Skip to content

Commit 18ccff4

Browse files
authored
Handle empty packages list in search (empty results). (#8934)
1 parent 2216593 commit 18ccff4

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

app/lib/search/mem_index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class InMemoryPackageIndex {
345345
/// The [BitArrayPool] does not reset the reused pool items, because initialization
346346
/// depends on the presence of the [filterOnPackages] list.
347347
void _resetBitArray(BitArray selected, List<String>? filterOnPackages) {
348-
if (filterOnPackages != null && filterOnPackages.isNotEmpty) {
348+
if (filterOnPackages != null) {
349349
selected.clearAll();
350350
for (final package in filterOnPackages) {
351351
final index = _nameToIndex[package];

app/lib/search/search_service.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ class ServiceSearchQuery {
237237
isNaturalOrder &&
238238
_hasNoOwnershipScope &&
239239
!_isFlutterFavorite &&
240-
(textMatchExtent ?? TextMatchExtent.api).shouldMatchApi();
240+
(textMatchExtent ?? TextMatchExtent.api).shouldMatchApi() &&
241+
packages == null;
241242

242243
/// Returns the validity status of the query.
243244
QueryValidity evaluateValidity() {

pkg/_pub_shared/lib/search/search_request_data.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ class SearchRequestData {
2828
this.offset,
2929
this.limit,
3030
this.textMatchExtent,
31-
List<String>? packages,
31+
this.packages,
3232
}) : query = _trimToNull(query),
33-
publisherId = _trimToNull(publisherId),
34-
packages = packages != null && packages.isNotEmpty ? packages : null;
33+
publisherId = _trimToNull(publisherId);
3534

3635
factory SearchRequestData.fromJson(Map<String, dynamic> json) =>
3736
_$SearchRequestDataFromJson(json);

pkg/pub_integration/test/like_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@ void main() {
7474

7575
await page.gotoOrigin('/experimental?my-liked-search=1');
7676

77+
// checking search with my-liked packages - without any likes
78+
await page.gotoOrigin('/packages?q=pkg+is:liked-by-me');
79+
final info1 = await listingPageInfo(page);
80+
expect(info1.packageNames, isEmpty);
81+
7782
await page.gotoOrigin('/packages/test_pkg');
7883
expect(await getCountLabels(), ['0', '0', '']);
7984

8085
await page.click('.like-button-and-label--button');
8186
await Future.delayed(Duration(seconds: 1));
8287
expect(await getCountLabels(), ['1', '1', '']);
8388

84-
// checking search with my-liked packages
89+
// checking search with my-liked packages - with the one liked package
8590
await page.gotoOrigin('/packages?q=pkg+is:liked-by-me');
86-
final info = await listingPageInfo(page);
87-
expect(info.packageNames.toSet(), {'test_pkg'});
91+
final info2 = await listingPageInfo(page);
92+
expect(info2.packageNames.toSet(), {'test_pkg'});
8893

8994
// displaying all three
9095
await page.gotoOrigin('/packages/test_pkg/score');

0 commit comments

Comments
 (0)