Skip to content

Commit

Permalink
Keep isSoftRemoved calls in-iteration, prevent List updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Dec 6, 2024
1 parent 428fc56 commit 72ba8c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/bin/tools/search_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Future<void> main(List<String> args) async {
json.decode(utf8.decode(gzip.decode(await file.readAsBytes())))
as Map<String, Object?>;
final snapshot = SearchSnapshot.fromJson(content);
snapshot.documents!
.removeWhere((packageName, doc) => isSoftRemoved(packageName));
final index = InMemoryPackageIndex(documents: snapshot.documents!.values);
final index = InMemoryPackageIndex(
documents:
snapshot.documents!.values.where((d) => !isSoftRemoved(d.package)));

// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
final queries = [
Expand Down
4 changes: 1 addition & 3 deletions app/lib/frontend/handlers/custom_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ Future<shelf.Response> apiPackageNamesHandler(shelf.Request request) async {

final bytes = await cache.packageNamesDataJsonGz().get(() async {
final packageNames = await nameTracker.getVisiblePackageNames();
packageNames.removeWhere(isSoftRemoved);

return gzip.encode(jsonUtf8Encoder.convert({
'packages': packageNames,
'packages': packageNames.where((p) => !isSoftRemoved(p)).toList(),
// pagination is off for now
'nextUrl': null,
}));
Expand Down
6 changes: 3 additions & 3 deletions app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class SearchBackend {
if (!claim.valid) {
return;
}
if (isSoftRemoved(package)) {
return;
}
// Skip if the last document timestamp is before [updated].
// 1-minute window is kept to reduce clock-skew.
if (updated != null) {
Expand Down Expand Up @@ -471,9 +474,6 @@ class SearchBackend {
return null;
}
final snapshot = SearchSnapshot.fromJson(map);
snapshot.documents!
.removeWhere((packageName, doc) => isSoftRemoved(packageName));

final count = snapshot.documents!.length;
_logger.info('Got $count packages from snapshot at ${snapshot.updated}');
return snapshot.documents?.values.toList();
Expand Down

0 comments on commit 72ba8c8

Please sign in to comment.