Skip to content

Commit 3f98201

Browse files
authored
Keep isSoftRemoved calls in-iteration, prevent List updates. (#8370)
1 parent 3e2dc43 commit 3f98201

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ 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({
8482
'packages': packageNames,
8583
// pagination is off for now

app/lib/package/name_tracker.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:clock/clock.dart';
88
import 'package:gcloud/service_scope.dart' as ss;
99
import 'package:logging/logging.dart';
1010
import 'package:meta/meta.dart';
11+
import 'package:pub_dev/package/overrides.dart';
1112
import 'package:pub_package_reader/pub_package_reader.dart';
1213

1314
import '../shared/datastore.dart';
@@ -51,7 +52,7 @@ class TrackedPackage {
5152
updated: p.updated!,
5253
latestVersion: p.latestVersion!,
5354
lastPublished: p.lastVersionPublished!,
54-
isVisible: p.isVisible,
55+
isVisible: p.isVisible && !isSoftRemoved(p.name!),
5556
);
5657

5758
@visibleForTesting
@@ -125,7 +126,7 @@ class NameTracker {
125126

126127
/// Get the names of all visible packages.
127128
///
128-
/// Packages that are _withdrawn_ are not listed here.
129+
/// Packages that are _moderated_ or _soft removed_ are NOT listed here.
129130
/// Packages that are _unlisted_ or _discontinued_ are **included in this list**.
130131
///
131132
/// If it is called before the first scan was done, it will wait for

app/lib/search/backend.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class SearchBackend {
132132
if (!claim.valid) {
133133
return;
134134
}
135+
if (isSoftRemoved(package)) {
136+
return;
137+
}
135138
// Skip if the last document timestamp is before [updated].
136139
// 1-minute window is kept to reduce clock-skew.
137140
if (updated != null) {
@@ -469,9 +472,6 @@ class SearchBackend {
469472
return null;
470473
}
471474
final snapshot = SearchSnapshot.fromJson(map);
472-
snapshot.documents!
473-
.removeWhere((packageName, doc) => isSoftRemoved(packageName));
474-
475475
final count = snapshot.documents!.length;
476476
_logger.info('Got $count packages from snapshot at ${snapshot.updated}');
477477
return snapshot.documents?.values.toList();

0 commit comments

Comments
 (0)