Skip to content

Commit 0156c36

Browse files
committed
Keep isSoftRemoved calls in-iteration, prevent List updates.
1 parent 537363a commit 0156c36

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

app/bin/tools/search_benchmark.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Future<void> main(List<String> args) async {
1919
json.decode(utf8.decode(gzip.decode(await file.readAsBytes())))
2020
as Map<String, Object?>;
2121
final snapshot = SearchSnapshot.fromJson(content);
22-
snapshot.documents!
23-
.removeWhere((packageName, doc) => isSoftRemoved(packageName));
24-
final index = InMemoryPackageIndex(documents: snapshot.documents!.values);
22+
final index = InMemoryPackageIndex(
23+
documents:
24+
snapshot.documents!.values.where((d) => !isSoftRemoved(d.package)));
2525

2626
// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
2727
final queries = [

app/lib/frontend/handlers/custom_api.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ Future<shelf.Response> apiPackageNamesHandler(shelf.Request request) async {
7878

7979
final bytes = await cache.packageNamesDataJsonGz().get(() async {
8080
final packageNames = await nameTracker.getVisiblePackageNames();
81-
packageNames.removeWhere(isSoftRemoved);
82-
8381
return gzip.encode(jsonUtf8Encoder.convert({
84-
'packages': packageNames,
82+
'packages': packageNames.where((p) => !isSoftRemoved(p)).toList(),
8583
// pagination is off for now
8684
'nextUrl': null,
8785
}));

app/lib/search/backend.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class SearchBackend {
133133
if (!claim.valid) {
134134
return;
135135
}
136+
if (isSoftRemoved(package)) {
137+
return;
138+
}
136139
// Skip if the last document timestamp is before [updated].
137140
// 1-minute window is kept to reduce clock-skew.
138141
if (updated != null) {
@@ -471,9 +474,6 @@ class SearchBackend {
471474
return null;
472475
}
473476
final snapshot = SearchSnapshot.fromJson(map);
474-
snapshot.documents!
475-
.removeWhere((packageName, doc) => isSoftRemoved(packageName));
476-
477477
final count = snapshot.documents!.length;
478478
_logger.info('Got $count packages from snapshot at ${snapshot.updated}');
479479
return snapshot.documents?.values.toList();

0 commit comments

Comments
 (0)