Skip to content

Commit 52597c5

Browse files
committed
Merge branch 'master' into misc/recommended-lint-progress
2 parents 4e505d8 + 0124843 commit 52597c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+732
-654
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ Important changes to data models, configuration, and migrations between each
22
AppEngine version, listed here to ease deployment and troubleshooting.
33

44
## Next Release (replace with git tag when deployed)
5+
6+
## `20241210t143600-all`
7+
* Bump runtimeVersion to `2024.12.09`.
8+
* Upgraded stable Dart analysis SDK to `3.6.0`
9+
* Upgraded pana to `0.22.17`.
510
* Note: `search` isolate renewal is randomized.
611

712
## `20241205t082000-all`

Dockerfile.worker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ RUN mkdir -p /home/worker/config/dart-stable
2323
RUN mkdir -p /home/worker/config/flutter-stable
2424

2525
# Setup Dart SDK into /home/worker/dart/{stable,preview}/
26-
RUN XDG_CONFIG_HOME=/home/worker/config/dart-stable tool/setup-dart.sh /home/worker/dart/stable 3.6.0-334.4.beta beta
26+
RUN XDG_CONFIG_HOME=/home/worker/config/dart-stable tool/setup-dart.sh /home/worker/dart/stable stable/raw/hash/ae7ca5199a0559db0ae60533e9cedd3ce0d6ab04
2727

2828
# Setup Flutter SDK into /home/worker/flutter/{stable,preview}/
2929
RUN XDG_CONFIG_HOME=/home/worker/config/flutter-stable tool/setup-flutter.sh /home/worker/flutter/stable 3.27.0-0.2.pre beta

app/bin/tools/search_benchmark.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:convert';
66
import 'dart:io';
77

8+
import 'package:_pub_shared/search/search_form.dart';
89
import 'package:pub_dev/package/overrides.dart';
910
import 'package:pub_dev/search/mem_index.dart';
1011
import 'package:pub_dev/search/models.dart';
@@ -24,6 +25,7 @@ Future<void> main(List<String> args) async {
2425

2526
// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
2627
final queries = [
28+
'chart',
2729
'json',
2830
'camera',
2931
'android camera',
@@ -33,7 +35,10 @@ Future<void> main(List<String> args) async {
3335
final sw = Stopwatch()..start();
3436
var count = 0;
3537
for (var i = 0; i < 100; i++) {
36-
index.search(ServiceSearchQuery.parse(query: queries[i % queries.length]));
38+
index.search(ServiceSearchQuery.parse(
39+
query: queries[i % queries.length],
40+
tagsPredicate: TagsPredicate.regularSearch(),
41+
));
3742
count++;
3843
}
3944
sw.stop();

app/lib/frontend/handlers/experimental.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ class ExperimentalFlags {
9595
bool get isDarkModeEnabled => isEnabled('dark');
9696
bool get isDarkModeDefault => isEnabled('dark-as-default');
9797

98-
bool get showDownloadCounts => isEnabled('download-counts');
98+
bool get showDownloadCountsVersionChart =>
99+
isEnabled('download-counts-version-chart');
100+
bool get showDownloadCounts => true;
99101

100102
String encodedAsCookie() => _enabled.join(':');
101103

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ d.Node labeledScoresNode({
2929
),
3030
d.div(
3131
classes: ['packages-score', 'packages-score-health'],
32-
child:
33-
_labeledScore('pub points', grantedPubPoints?.toString(), sign: ''),
32+
child: _labeledScore('points', grantedPubPoints?.toString(), sign: ''),
3433
),
3534
requestContext.experimentalFlags.showDownloadCounts
3635
? d.div(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ d.Node scoreTabNode({
8080
),
8181
_reportNode(report),
8282
if (card.weeklyVersionDownloads != null &&
83-
requestContext.experimentalFlags.showDownloadCounts)
83+
requestContext.experimentalFlags.showDownloadCountsVersionChart)
8484
_downloadsChart(card.weeklyVersionDownloads!),
8585
if (toolEnvInfo != null) toolEnvInfo,
8686
]),

app/lib/search/mem_index.dart

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class InMemoryPackageIndex {
2828
late final TokenIndex<String> _readmeIndex;
2929
late final TokenIndex<IndexedApiDocPage> _apiSymbolIndex;
3030
late final _scorePool = ScorePool(_packageNameIndex._packageNames);
31+
final _tagIds = <String, int>{};
32+
final _documentTagIds = <List<int>>[];
3133

3234
/// Adjusted score takes the overall score and transforms
3335
/// it linearly into the [0.4-1.0] range.
@@ -58,6 +60,14 @@ class InMemoryPackageIndex {
5860
final doc = _documents[i];
5961
_documentsByName[doc.package] = doc;
6062

63+
// transform tags into numberical IDs
64+
final tagIds = <int>[];
65+
for (final tag in doc.tags) {
66+
tagIds.add(_tagIds.putIfAbsent(tag, () => _tagIds.length));
67+
}
68+
tagIds.sort();
69+
_documentTagIds.add(tagIds);
70+
6171
final apiDocPages = doc.apiDocPages;
6272
if (apiDocPages != null) {
6373
for (final page in apiDocPages) {
@@ -122,6 +132,14 @@ class InMemoryPackageIndex {
122132
}
123133

124134
PackageSearchResult search(ServiceSearchQuery query) {
135+
// prevent any work if offset is outside of the range
136+
if ((query.offset ?? 0) > _documents.length) {
137+
return PackageSearchResult(
138+
timestamp: clock.now(),
139+
totalCount: 0,
140+
packageHits: [],
141+
);
142+
}
125143
return _scorePool.withScore(
126144
value: 1.0,
127145
fn: (score) {
@@ -144,8 +162,49 @@ class InMemoryPackageIndex {
144162
final combinedTagsPredicate =
145163
query.tagsPredicate.appendPredicate(query.parsedQuery.tagsPredicate);
146164
if (combinedTagsPredicate.isNotEmpty) {
147-
packageScores.retainWhere(
148-
(i, _) => combinedTagsPredicate.matches(_documents[i].tagsForLookup));
165+
// The list of predicate tag entries, converted to tag IDs (or -1 if there is no indexed tag),
166+
// sorted by their id.
167+
final entriesToCheck = combinedTagsPredicate.entries
168+
.map((e) => MapEntry(_tagIds[e.key] ?? -1, e.value))
169+
.toList()
170+
..sort((a, b) => a.key.compareTo(b.key));
171+
172+
packageScores.retainWhere((docIndex, _) {
173+
// keeping track of tag id iteration with the `nextTagIndex`
174+
final tagIds = _documentTagIds[docIndex];
175+
var nextTagIndex = 0;
176+
177+
for (final entry in entriesToCheck) {
178+
if (entry.key == -1) {
179+
// no tag id is present for this predicate
180+
if (entry.value) {
181+
// the predicate is required, no document will match it
182+
return false;
183+
} else {
184+
// the predicate is prohibited, no document has it, always a match
185+
continue;
186+
}
187+
}
188+
189+
// skipping the present tag ids until the currently matched predicate tag id
190+
while (nextTagIndex < tagIds.length &&
191+
tagIds[nextTagIndex] < entry.key) {
192+
nextTagIndex++;
193+
}
194+
195+
// checking presence
196+
late bool present;
197+
if (nextTagIndex == tagIds.length) {
198+
present = false;
199+
} else {
200+
present = tagIds[nextTagIndex] == entry.key;
201+
}
202+
203+
if (entry.value && !present) return false;
204+
if (!entry.value && present) return false;
205+
}
206+
return true;
207+
});
149208
}
150209

151210
// filter on dependency
@@ -213,10 +272,12 @@ class InMemoryPackageIndex {
213272
/// it linearly into the [0.4-1.0] range, to allow better
214273
/// multiplication outcomes.
215274
packageScores.multiplyAllFromValues(_adjustedOverallScores);
216-
indexedHits = _rankWithValues(packageScores);
275+
indexedHits = _rankWithValues(packageScores,
276+
requiredLengthThreshold: query.offset);
217277
break;
218278
case SearchOrder.text:
219-
indexedHits = _rankWithValues(packageScores);
279+
indexedHits = _rankWithValues(packageScores,
280+
requiredLengthThreshold: query.offset);
220281
break;
221282
case SearchOrder.created:
222283
indexedHits = _createdOrderedHits.whereInScores(packageScores);
@@ -395,21 +456,29 @@ class InMemoryPackageIndex {
395456
return null;
396457
}
397458

398-
List<IndexedPackageHit> _rankWithValues(IndexedScore<String> score) {
459+
List<IndexedPackageHit> _rankWithValues(
460+
IndexedScore<String> score, {
461+
// if the item count is fewer than this threshold, an empty list will be returned
462+
int? requiredLengthThreshold,
463+
}) {
399464
final list = <IndexedPackageHit>[];
400465
for (var i = 0; i < score.length; i++) {
401466
final value = score.getValue(i);
402467
if (value <= 0.0) continue;
403468
list.add(IndexedPackageHit(
404469
i, PackageHit(package: score.keys[i], score: value)));
405470
}
471+
if ((requiredLengthThreshold ?? 0) > list.length) {
472+
// There is no point to sort or even keep the results, as the search query offset ignores these anyway.
473+
return [];
474+
}
406475
list.sort((a, b) {
407476
final scoreCompare = -a.hit.score!.compareTo(b.hit.score!);
408477
if (scoreCompare != 0) return scoreCompare;
409478
// if two packages got the same score, order by last updated
410479
return _compareUpdated(_documents[a.index], _documents[b.index]);
411480
});
412-
return list.toList();
481+
return list;
413482
}
414483

415484
List<IndexedPackageHit> _rankWithComparator(

app/lib/search/search_service.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ class PackageDocument {
135135

136136
Map<String, dynamic> toJson() => _$PackageDocumentToJson(this);
137137

138-
@JsonKey(includeFromJson: false, includeToJson: false)
139-
late final Set<String> tagsForLookup = Set.of(tags);
140-
141138
late final packageNameLowerCased = package.toLowerCase();
142139
}
143140

app/lib/search/text_utils.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ Map<String, double>? tokenize(String? originalText, {bool isSplit = false}) {
102102

103103
// Scan for CamelCase phrases and extract Camel and Case separately.
104104
final wordCodeUnits = word.codeUnits;
105-
final changeIndex = <int>[0];
106105
bool prevLower = _isLower(wordCodeUnits[0]);
107-
for (int i = 1; i < word.length; i++) {
108-
final lower = _isLower(wordCodeUnits[i]);
109-
if (!lower && prevLower) {
110-
changeIndex.add(i);
106+
int prevIndex = 0;
107+
for (int i = 1; i <= word.length; i++) {
108+
if (i < word.length) {
109+
final lower = _isLower(wordCodeUnits[i]);
110+
final isChanging = !lower && prevLower;
111+
prevLower = lower;
112+
if (!isChanging) continue;
111113
}
112-
prevLower = lower;
113-
}
114-
changeIndex.add(word.length);
115-
for (int i = 1; i < changeIndex.length; i++) {
116-
final token = normalizeBeforeIndexing(
117-
word.substring(changeIndex[i - 1], changeIndex[i]));
114+
115+
final token = normalizeBeforeIndexing(word.substring(prevIndex, i));
118116
final weight = math.pow((token.length / word.length), 0.5).toDouble();
119117
if ((tokens[token] ?? 0.0) < weight) {
120118
tokens[token] = weight;
121119
}
120+
121+
prevIndex = i;
122122
}
123123
}
124124
return tokens;

app/lib/shared/versions.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ final RegExp runtimeVersionPattern = RegExp(r'^\d{4}\.\d{2}\.\d{2}$');
2424
/// when the version switch happens.
2525
const _acceptedRuntimeVersions = <String>[
2626
// The current [runtimeVersion].
27-
'2024.12.04',
27+
'2024.12.09',
2828
// Fallback runtime versions.
29+
'2024.12.04',
2930
'2024.11.21',
30-
'2024.11.18',
3131
];
3232

3333
/// Sets the current runtime versions.
@@ -62,7 +62,7 @@ bool shouldGCVersion(String version) =>
6262

6363
// keep in-sync with SDK version in .mono_repo.yml and Dockerfile
6464
final String runtimeSdkVersion = '3.5.0';
65-
final String toolStableDartSdkVersion = '3.6.0-334.4.beta';
65+
final String toolStableDartSdkVersion = '3.6.0';
6666
final String toolStableFlutterSdkVersion = '3.27.0-0.2.pre';
6767

6868
final semanticToolStableDartSdkVersion =

0 commit comments

Comments
 (0)