Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit e30e3ed

Browse files
authored
bundle analysis: fix unknown asset size compute (#914)
1 parent 3d8af18 commit e30e3ed

File tree

2 files changed

+168
-1
lines changed

2 files changed

+168
-1
lines changed

graphql_api/tests/test_bundle_analysis_measurements.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,3 +2971,162 @@ def test_bundle_report_bad_data_check(self, get_storage_service):
29712971
"name": "super",
29722972
},
29732973
}
2974+
2975+
@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
2976+
def test_bundle_report_measurements_only_unknown(self, get_storage_service):
2977+
storage = MemoryStorageService({})
2978+
get_storage_service.return_value = storage
2979+
2980+
with open("./services/tests/samples/bundle_with_uuid.sqlite", "rb") as f:
2981+
storage_path = StoragePaths.bundle_report.path(
2982+
repo_key=ArchiveService.get_archive_hash(self.repo),
2983+
report_key=self.head_commit_report.external_id,
2984+
)
2985+
storage.write_file(get_bucket_name(), storage_path, f)
2986+
2987+
query = """
2988+
query FetchMeasurements(
2989+
$org: String!,
2990+
$repo: String!,
2991+
$commit: String!
2992+
$filters: BundleAnalysisMeasurementsSetFilters
2993+
$orderingDirection: OrderingDirection!
2994+
$interval: MeasurementInterval!
2995+
$before: DateTime!
2996+
$after: DateTime!
2997+
) {
2998+
owner(username: $org) {
2999+
repository(name: $repo) {
3000+
... on Repository {
3001+
commit(id: $commit) {
3002+
bundleAnalysis {
3003+
bundleAnalysisReport {
3004+
__typename
3005+
... on BundleAnalysisReport {
3006+
bundle(name: "super") {
3007+
name
3008+
measurements(
3009+
filters: $filters
3010+
orderingDirection: $orderingDirection
3011+
after: $after
3012+
interval: $interval
3013+
before: $before
3014+
){
3015+
assetType
3016+
name
3017+
size {
3018+
loadTime {
3019+
threeG
3020+
highSpeed
3021+
}
3022+
size {
3023+
gzip
3024+
uncompress
3025+
}
3026+
}
3027+
change {
3028+
loadTime {
3029+
threeG
3030+
highSpeed
3031+
}
3032+
size {
3033+
gzip
3034+
uncompress
3035+
}
3036+
}
3037+
measurements {
3038+
avg
3039+
min
3040+
max
3041+
timestamp
3042+
}
3043+
}
3044+
}
3045+
}
3046+
}
3047+
}
3048+
}
3049+
}
3050+
}
3051+
}
3052+
}
3053+
"""
3054+
3055+
# Test without using asset type filters
3056+
variables = {
3057+
"org": self.org.username,
3058+
"repo": self.repo.name,
3059+
"commit": self.commit.commitid,
3060+
"orderingDirection": "ASC",
3061+
"interval": "INTERVAL_1_DAY",
3062+
"after": "2024-06-06",
3063+
"before": "2024-06-10",
3064+
"filters": {"assetTypes": ["UNKNOWN_SIZE"]},
3065+
}
3066+
data = self.gql_request(query, variables=variables)
3067+
commit = data["owner"]["repository"]["commit"]
3068+
3069+
assert commit["bundleAnalysis"]["bundleAnalysisReport"] == {
3070+
"__typename": "BundleAnalysisReport",
3071+
"bundle": {
3072+
"measurements": [
3073+
{
3074+
"assetType": "UNKNOWN_SIZE",
3075+
"change": {
3076+
"loadTime": {
3077+
"highSpeed": 0,
3078+
"threeG": 0,
3079+
},
3080+
"size": {
3081+
"gzip": 0,
3082+
"uncompress": 0,
3083+
},
3084+
},
3085+
"measurements": [
3086+
{
3087+
"avg": 0.0,
3088+
"max": 0.0,
3089+
"min": 0.0,
3090+
"timestamp": "2024-06-06T00:00:00+00:00",
3091+
},
3092+
{
3093+
"avg": None,
3094+
"max": None,
3095+
"min": None,
3096+
"timestamp": "2024-06-07T00:00:00+00:00",
3097+
},
3098+
{
3099+
"avg": None,
3100+
"max": None,
3101+
"min": None,
3102+
"timestamp": "2024-06-08T00:00:00+00:00",
3103+
},
3104+
{
3105+
"avg": None,
3106+
"max": None,
3107+
"min": None,
3108+
"timestamp": "2024-06-09T00:00:00+00:00",
3109+
},
3110+
{
3111+
"avg": 0.0,
3112+
"max": 0.0,
3113+
"min": 0.0,
3114+
"timestamp": "2024-06-10T00:00:00+00:00",
3115+
},
3116+
],
3117+
"name": None,
3118+
"size": {
3119+
"loadTime": {
3120+
"highSpeed": 0,
3121+
"threeG": 0,
3122+
},
3123+
"size": {
3124+
"gzip": 0,
3125+
"uncompress": 0,
3126+
},
3127+
},
3128+
},
3129+
],
3130+
"name": "super",
3131+
},
3132+
}

graphql_api/types/bundle_analysis/base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,18 @@ def resolve_bundle_report_measurements(
299299
)
300300

301301
# All measureable names we need to fetch to compute the requested asset types
302-
if not asset_types or ASSET_TYPE_UNKNOWN in asset_types:
302+
if not asset_types:
303303
measurables_to_fetch = [
304304
item for item in list(BundleAnalysisMeasurementsAssetType)
305305
]
306+
elif ASSET_TYPE_UNKNOWN in asset_types:
307+
measurables_to_fetch = [
308+
BundleAnalysisMeasurementsAssetType.REPORT_SIZE,
309+
BundleAnalysisMeasurementsAssetType.JAVASCRIPT_SIZE,
310+
BundleAnalysisMeasurementsAssetType.STYLESHEET_SIZE,
311+
BundleAnalysisMeasurementsAssetType.FONT_SIZE,
312+
BundleAnalysisMeasurementsAssetType.IMAGE_SIZE,
313+
]
306314
else:
307315
measurables_to_fetch = [
308316
BundleAnalysisMeasurementsAssetType[item] for item in asset_types

0 commit comments

Comments
 (0)