Skip to content

Commit df251ef

Browse files
authored
Strip some of the license coverage data if the report would be over the size limit. (#8979)
1 parent f436420 commit df251ef

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

pkg/pub_worker/lib/src/bin/pana_wrapper.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,31 @@ Future<void> main(List<String> args) async {
131131
);
132132

133133
// sanity check on pana report size
134-
final reportSize = gzip
134+
var reportSize = gzip
135135
.encode(utf8.encode(json.encode(summary.toJson())))
136136
.length;
137+
138+
// Note: the new license coverage data seems to generate coverage pairs that
139+
// occupy way too much space. Until that bug is fixed, we should remove
140+
// that data from the summary.
141+
// TODO: remove this block once https://github.com/dart-lang/pana/issues/1481 gets fixed and deployed
142+
if (reportSize > _reportSizeDropThreshold) {
143+
// We are storing the licenses in two fields, removing the fallback/unused one.
144+
// ignore: deprecated_member_use
145+
summary.licenses?.clear();
146+
147+
// Remove excessive range data.
148+
for (final l in summary.result?.licenses ?? <License>[]) {
149+
final count = l.range?.coverages.length ?? 0;
150+
if (count > 50) {
151+
l.range?.coverages.removeRange(50, count);
152+
}
153+
}
154+
155+
// re-calculate report size
156+
reportSize = gzip.encode(utf8.encode(json.encode(summary.toJson()))).length;
157+
}
158+
137159
if (reportSize > _reportSizeDropThreshold) {
138160
summary = Summary(
139161
createdAt: summary.createdAt,

0 commit comments

Comments
 (0)