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

Commit 668e8d1

Browse files
authored
bundle analysis: calculate bundle's total gzip size correctly (#803)
1 parent f840fed commit 668e8d1

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed

graphql_api/tests/test_commit.py

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ def test_bundle_analysis_report(self, get_storage_service):
12761276
"highSpeed": 0,
12771277
},
12781278
"size": {
1279-
"gzip": 1,
1279+
"gzip": 0,
12801280
"uncompress": 1500,
12811281
},
12821282
},
@@ -1934,3 +1934,102 @@ def test_fetch_commit_status_pending(self):
19341934
commit = data["owner"]["repository"]["commit"]
19351935
assert commit["coverageStatus"] == CommitStatus.PENDING.value
19361936
assert commit["bundleStatus"] == CommitStatus.PENDING.value
1937+
1938+
@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
1939+
def test_bundle_analysis_report_gzip_size_total(self, get_storage_service):
1940+
storage = MemoryStorageService({})
1941+
get_storage_service.return_value = storage
1942+
1943+
head_commit_report = CommitReportFactory(
1944+
commit=self.commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
1945+
)
1946+
1947+
with open(
1948+
"./services/tests/samples/head_bundle_report_with_gzip_size.sqlite", "rb"
1949+
) as f:
1950+
storage_path = StoragePaths.bundle_report.path(
1951+
repo_key=ArchiveService.get_archive_hash(self.repo),
1952+
report_key=head_commit_report.external_id,
1953+
)
1954+
storage.write_file(get_bucket_name(), storage_path, f)
1955+
1956+
query = """
1957+
query FetchCommit($org: String!, $repo: String!, $commit: String!) {
1958+
owner(username: $org) {
1959+
repository(name: $repo) {
1960+
... on Repository {
1961+
commit(id: $commit) {
1962+
bundleAnalysisReport {
1963+
__typename
1964+
... on BundleAnalysisReport {
1965+
bundles {
1966+
name
1967+
bundleData {
1968+
size {
1969+
gzip
1970+
uncompress
1971+
}
1972+
}
1973+
}
1974+
}
1975+
}
1976+
}
1977+
}
1978+
}
1979+
}
1980+
}
1981+
"""
1982+
1983+
variables = {
1984+
"org": self.org.username,
1985+
"repo": self.repo.name,
1986+
"commit": self.commit.commitid,
1987+
}
1988+
data = self.gql_request(query, variables=variables)
1989+
commit = data["owner"]["repository"]["commit"]
1990+
1991+
assert commit["bundleAnalysisReport"] == {
1992+
"__typename": "BundleAnalysisReport",
1993+
"bundles": [
1994+
{
1995+
# All assets non compressible
1996+
"name": "b1",
1997+
"bundleData": {
1998+
"size": {
1999+
"gzip": 20,
2000+
"uncompress": 20,
2001+
},
2002+
},
2003+
},
2004+
{
2005+
# Some assets non compressible
2006+
"name": "b2",
2007+
"bundleData": {
2008+
"size": {
2009+
"gzip": 198,
2010+
"uncompress": 200,
2011+
},
2012+
},
2013+
},
2014+
{
2015+
# All assets non compressible
2016+
"name": "b3",
2017+
"bundleData": {
2018+
"size": {
2019+
"gzip": 1495,
2020+
"uncompress": 1500,
2021+
},
2022+
},
2023+
},
2024+
{
2025+
# All assets non compressible
2026+
"name": "b5",
2027+
"bundleData": {
2028+
"size": {
2029+
"gzip": 199995,
2030+
"uncompress": 200000,
2031+
},
2032+
},
2033+
},
2034+
],
2035+
}

graphql_api/types/bundle_analysis/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ def resolve_asset(
146146
def resolve_bundle_data(
147147
bundle_report: BundleReport, info: GraphQLResolveInfo
148148
) -> BundleData:
149-
return BundleData(bundle_report.size_total)
149+
return BundleData(
150+
bundle_report.size_total,
151+
bundle_report.gzip_size_total,
152+
)
150153

151154

152155
@bundle_report_bindable.field("measurements")

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ factory-boy
2020
fakeredis
2121
freezegun
2222
https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem
23-
https://github.com/codecov/shared/archive/42f83ec717e632c543cc6ceab8fc3cc39eccc5be.tar.gz#egg=shared
23+
https://github.com/codecov/shared/archive/87495b40c8e0af14a9d093946aa3cac2094b1de8.tar.gz#egg=shared
2424
google-cloud-pubsub
2525
gunicorn>=22.0.0
2626
https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ sentry-sdk[celery]==2.13.0
417417
# shared
418418
setproctitle==1.1.10
419419
# via -r requirements.in
420-
shared @ https://github.com/codecov/shared/archive/42f83ec717e632c543cc6ceab8fc3cc39eccc5be.tar.gz
420+
shared @ https://github.com/codecov/shared/archive/87495b40c8e0af14a9d093946aa3cac2094b1de8.tar.gz
421421
# via -r requirements.in
422422
simplejson==3.17.2
423423
# via -r requirements.in

services/bundle_analysis.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def asset(self, name: str) -> Optional[AssetReport]:
263263
def size_total(self) -> int:
264264
return self.report.total_size(**self.filters)
265265

266+
@cached_property
267+
def gzip_size_total(self) -> int:
268+
return self.report.total_gzip_size(**self.filters)
269+
266270
@cached_property
267271
def module_extensions(self) -> List[str]:
268272
extensions = set()
Binary file not shown.

0 commit comments

Comments
 (0)