Skip to content

Commit 00f53e0

Browse files
authored
Code cleanup: renaming isSoftDeleted -> isSdkPackage. (#8749)
1 parent 5823b79 commit 00f53e0

File tree

9 files changed

+23
-20
lines changed

9 files changed

+23
-20
lines changed

app/bin/tools/search_benchmark.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Future<void> main(List<String> args) async {
2121
final snapshot = SearchSnapshot.fromJson(content);
2222
final index = InMemoryPackageIndex(
2323
documents:
24-
snapshot.documents!.values.where((d) => !isSoftRemoved(d.package)));
24+
snapshot.documents!.values.where((d) => !isSdkPackage(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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import 'cache_control.dart';
3838
Future<shelf.Response> apiDocumentationHandler(
3939
shelf.Request request, String package) async {
4040
checkPackageVersionParams(package);
41-
if (isSoftRemoved(package)) {
41+
if (isSdkPackage(package)) {
4242
return jsonResponse({}, status: 404);
4343
}
4444

app/lib/frontend/handlers/documentation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Future<shelf.Response> documentationHandler(shelf.Request request) async {
2828
return notFoundHandler(request);
2929
}
3030
checkPackageVersionParams(docFilePath.package, docFilePath.version);
31-
if (redirectPackageUrls.containsKey(docFilePath.package)) {
32-
return redirectResponse(redirectPackageUrls[docFilePath.package]!);
31+
if (isSdkPackage(docFilePath.package)) {
32+
return redirectResponse(sdkPackageUrls[docFilePath.package]!);
3333
}
3434
if (!await packageBackend.isPackageVisible(docFilePath.package)) {
3535
return notFoundHandler(request);

app/lib/frontend/handlers/package.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ Future<shelf.Response> packageScoreLogTxtHandler(
233233
String? version,
234234
}) async {
235235
checkPackageVersionParams(package, version);
236-
if (redirectPackageUrls.containsKey(package)) {
237-
return redirectResponse(redirectPackageUrls[package]!);
236+
if (isSdkPackage(package)) {
237+
return redirectResponse(sdkPackageUrls[package]!);
238238
}
239239
if (!await packageBackend.isPackageVisible(package)) {
240240
return shelf.Response.notFound('no such package');
@@ -289,8 +289,8 @@ Future<shelf.Response> _handlePackagePage({
289289
if (request.requestedUri.path != canonicalUrl) {
290290
return redirectResponse(canonicalUrl);
291291
}
292-
if (redirectPackageUrls.containsKey(packageName)) {
293-
return redirectResponse(redirectPackageUrls[packageName]!);
292+
if (isSdkPackage(packageName)) {
293+
return redirectResponse(sdkPackageUrls[packageName]!);
294294
}
295295
final Stopwatch sw = Stopwatch()..start();
296296
String? cachedPage;

app/lib/frontend/templates/views/pkg/info_box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:pub_dev/service/download_counts/download_counts.dart';
88
import 'package:pubspec_parse/pubspec_parse.dart' as pubspek;
99

1010
import '../../../../package/models.dart';
11-
import '../../../../package/overrides.dart' show redirectPackageUrls;
11+
import '../../../../package/overrides.dart' show sdkPackageUrls;
1212
import '../../../../package/screenshots/backend.dart';
1313
import '../../../../service/topics/models.dart';
1414
import '../../../../shared/urls.dart' as urls;
@@ -238,7 +238,7 @@ d.Node? _dependencyListNode(Map<String, pubspek.Dependency>? dependencies) {
238238
nodes.add(d.text(', '));
239239
}
240240
final dep = dependencies[p];
241-
var href = redirectPackageUrls[p];
241+
var href = sdkPackageUrls[p];
242242
String? constraint;
243243
if (href == null && dep is pubspek.HostedDependency) {
244244
href = urls.pkgPageUrl(p);

app/lib/package/backend.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class PackageBackend {
137137
.run()
138138
.where((p) => p.isVisible)
139139
.where((p) => p.isIncludedInRobots)
140-
.where((p) => !isSoftRemoved(p.name!));
140+
.where((p) => !isSdkPackage(p.name!));
141141
}
142142

143143
/// Retrieves package versions ordered by their published date descending.
@@ -150,7 +150,7 @@ class PackageBackend {
150150
final versions = await query.run().toList();
151151
final results = <PackageVersion>[];
152152
for (final v in versions) {
153-
if (isSoftRemoved(v.package)) continue;
153+
if (isSdkPackage(v.package)) continue;
154154
if (!(await isPackageVisible(v.package))) continue;
155155
results.add(v);
156156
}
@@ -1011,7 +1011,7 @@ class PackageBackend {
10111011
// purpose of checking if the dependency exists, we skip them.
10121012
continue;
10131013
}
1014-
if (isSoftRemoved(name)) {
1014+
if (isSdkPackage(name)) {
10151015
continue;
10161016
}
10171017
if (nameTracker.hasPackage(name)) {

app/lib/package/name_tracker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TrackedPackage {
5252
updated: p.updated!,
5353
latestVersion: p.latestVersion!,
5454
lastPublished: p.lastVersionPublished!,
55-
isVisible: p.isVisible && !isSoftRemoved(p.name!),
55+
isVisible: p.isVisible && !isSdkPackage(p.name!),
5656
);
5757

5858
@visibleForTesting

app/lib/package/overrides.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ final _reservedPackageNames = <String>[
4747
'flutterkit',
4848
].map(reducePackageName).toList();
4949

50-
const redirectPackageUrls = <String, String>{
50+
/// Mapping packages names to URLs that we need to redirect them to after they become SDK packages.
51+
const sdkPackageUrls = <String, String>{
5152
'flutter': 'https://api.flutter.dev/',
5253
'flutter_driver':
5354
'https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html',
@@ -81,10 +82,12 @@ const devDependencyPackages = <String>{
8182
'test_process',
8283
};
8384

84-
/// A package is soft-removed when we keep it in the archives and index, but we
85-
/// won't serve the package or the documentation page, or any data about it.
86-
bool isSoftRemoved(String packageName) =>
87-
redirectPackageUrls.containsKey(packageName);
85+
/// A package may become an SDK package, after which we redirect
86+
/// their UI page to a new location.
87+
///
88+
/// Note: we keep them in the archives, and keep serving their API information.
89+
bool isSdkPackage(String packageName) =>
90+
sdkPackageUrls.containsKey(packageName);
8891

8992
/// Whether the [name] is (very similar) to a reserved package name.
9093
bool matchesReservedPackageName(String name) =>

app/lib/search/backend.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class SearchBackend {
151151
if (!claim.valid) {
152152
return;
153153
}
154-
if (isSoftRemoved(package)) {
154+
if (isSdkPackage(package)) {
155155
return;
156156
}
157157
// Skip if the last document timestamp is before [updated].

0 commit comments

Comments
 (0)