Skip to content

Commit 3a02414

Browse files
committed
Prefer versions with documentation when selecting redirect target on /documentation/ URLs.
1 parent ba053e6 commit 3a02414

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

app/lib/frontend/handlers/documentation.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ Future<ResolvedDocUrlVersion> _resolveDocUrlVersion(
167167
}
168168

169169
// Select the closest version (may be the same as version) that has a finished analysis.
170-
final closest = await taskBackend.closestFinishedVersion(package, version);
170+
final closest = await taskBackend.closestFinishedVersion(
171+
package,
172+
version,
173+
preferDocsCompleted: true,
174+
);
171175
return ResolvedDocUrlVersion(
172176
version: closest ?? version,
173177
urlSegment: closest ?? version,

app/lib/task/backend.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,15 @@ class TaskBackend {
10961096
/// If [version] or newer exists with finished analysis, it will be preferred, otherwise
10971097
/// older versions may be considered too.
10981098
///
1099+
/// When [preferDocsCompleted] is set, a successfully completed but potentially older
1100+
/// version is preferred over a completed version without documentation.
1101+
///
10991102
/// Returns `null` if no such version exists.
1100-
Future<String?> closestFinishedVersion(String package, String version) async {
1103+
Future<String?> closestFinishedVersion(
1104+
String package,
1105+
String version, {
1106+
bool preferDocsCompleted = false,
1107+
}) async {
11011108
final cachedValue =
11021109
await cache.closestFinishedVersion(package, version).get(() async {
11031110
final semanticVersion = Version.parse(version);
@@ -1108,7 +1115,19 @@ class TaskBackend {
11081115
if (state == null || state.hasNeverFinished) {
11091116
continue;
11101117
}
1111-
final candidates = state.versions?.entries
1118+
List<Version>? candidates;
1119+
if (preferDocsCompleted) {
1120+
final finishedDocCandidates = state.versions?.entries
1121+
.where((e) => e.value.docs)
1122+
.map((e) => Version.parse(e.key))
1123+
.toList();
1124+
if (finishedDocCandidates != null &&
1125+
finishedDocCandidates.isNotEmpty) {
1126+
candidates = finishedDocCandidates;
1127+
}
1128+
}
1129+
1130+
candidates ??= state.versions?.entries
11121131
.where((e) => e.value.finished)
11131132
.map((e) => Version.parse(e.key))
11141133
.toList();

0 commit comments

Comments
 (0)