Skip to content

Commit

Permalink
Bundle Analysis: fix routes and add sizes to RouteChange
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySentry committed Dec 5, 2024
1 parent cda7ef6 commit 570e388
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 8 additions & 0 deletions shared/bundle_analysis/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class RouteChange(BaseChange):

route_name: str
percentage_delta: float
size_base: int
size_head: int


@dataclass(frozen=True)
Expand Down Expand Up @@ -222,6 +224,8 @@ def size_changes(self) -> List[RouteChange]:
change_type=RouteChange.ChangeType.ADDED,
size_delta=head_sizes[route_name],
percentage_delta=100,
size_base=0,
size_head=head_sizes[route_name],
)
)
# Removed old route
Expand All @@ -232,6 +236,8 @@ def size_changes(self) -> List[RouteChange]:
change_type=RouteChange.ChangeType.REMOVED,
size_delta=-base_sizes[route_name],
percentage_delta=-100.0,
size_base=base_sizes[route_name],
size_head=0,
)
)
# Changed
Expand All @@ -244,6 +250,8 @@ def size_changes(self) -> List[RouteChange]:
change_type=RouteChange.ChangeType.CHANGED,
size_delta=size_delta,
percentage_delta=percentage_delta,
size_base=base_sizes[route_name],
size_head=head_sizes[route_name],
)
)

Expand Down
6 changes: 4 additions & 2 deletions shared/bundle_analysis/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ def routes(self) -> Dict[str, List[AssetReport]]:
"""
route_map = defaultdict(list)
for asset_report in self.asset_reports():
for route in asset_report.routes():
route_map[route].append(asset_report)
routes = asset_report.routes()
if routes is not None:
for route in routes:
route_map[route].append(asset_report)
return route_map

@sentry_sdk.trace
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/bundle_analysis/test_bundle_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,32 @@ def test_bundle_analysis_route_comparison_by_bundle_name():
change_type=AssetChange.ChangeType.CHANGED,
size_delta=900,
percentage_delta=810.81,
size_base=111,
size_head=1011,
),
RouteChange(
route_name="/sverdle/faq",
change_type=AssetChange.ChangeType.REMOVED,
size_delta=-110,
percentage_delta=-100.0,
size_base=110,
size_head=0,
),
RouteChange(
route_name="/sverdle/faq-prime",
change_type=AssetChange.ChangeType.ADDED,
size_delta=1010,
percentage_delta=100,
size_base=0,
size_head=1010,
),
RouteChange(
route_name="/sverdle/users",
change_type=AssetChange.ChangeType.CHANGED,
size_delta=900,
percentage_delta=810.81,
size_base=111,
size_head=1011,
),
]

Expand Down Expand Up @@ -306,24 +314,32 @@ def test_bundle_analysis_route_comparison_all_bundles():
change_type=AssetChange.ChangeType.CHANGED,
size_delta=900,
percentage_delta=810.81,
size_base=111,
size_head=1011,
),
RouteChange(
route_name="/sverdle/faq",
change_type=AssetChange.ChangeType.REMOVED,
size_delta=-110,
percentage_delta=-100.0,
size_base=110,
size_head=0,
),
RouteChange(
route_name="/sverdle/faq-prime",
change_type=AssetChange.ChangeType.ADDED,
size_delta=1010,
percentage_delta=100,
size_base=0,
size_head=1010,
),
RouteChange(
route_name="/sverdle/users",
change_type=AssetChange.ChangeType.CHANGED,
size_delta=900,
percentage_delta=810.81,
size_base=111,
size_head=1011,
),
]
assert sorted_route_changes == expected_bundle1_changes
Expand All @@ -335,24 +351,32 @@ def test_bundle_analysis_route_comparison_all_bundles():
change_type=AssetChange.ChangeType.CHANGED,
size_delta=9999,
percentage_delta=9008.11,
size_base=111,
size_head=10110,
),
RouteChange(
route_name="/sverdle/faq",
change_type=AssetChange.ChangeType.REMOVED,
size_delta=-110,
percentage_delta=-100.0,
size_base=110,
size_head=0,
),
RouteChange(
route_name="/sverdle/faq-prime",
change_type=AssetChange.ChangeType.ADDED,
size_delta=10100,
percentage_delta=100,
size_base=0,
size_head=10100,
),
RouteChange(
route_name="/sverdle/users",
change_type=AssetChange.ChangeType.CHANGED,
size_delta=9999,
percentage_delta=9008.11,
size_base=111,
size_head=10110,
),
]
assert sorted_route_changes == expected_bundle2_changes
Expand Down

0 comments on commit 570e388

Please sign in to comment.