refactor(DotcomWeb.ModeView): simpler has_alert? - #3379
Merged
Conversation
lvachon1
approved these changes
Jul 31, 2026
lvachon1
left a comment
Contributor
There was a problem hiding this comment.
Looks nice, runs great, and I learned some new syntax tricks from reading this PR. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
The homepage's "Recently Visited" section shows routes. If a route has an important alert, we show our familiar triangle warning icon.
My local load testing on the homepage has found that fetching and processing alerts is by far the most computationally intensive part of the homepage. The "Recently Visited" buttons are a small part of what we do with homepage alerts, but I wanted to see if I could make it a bit more performant.
Implementation
Instead of having the homepage fetch every alert and then having the view check the list of all alerts for whether a given route is present, I wrote a helper function to more directly assess whether a route has a high priority alert.
The first two commits assemble the needed queries:
feat(Alerts.Cache.Store): get from ids + priority
We already have functions to easily and performantly get a list of alert IDs associated with a route ID. I wanted to build upon that by making it just as easy to find which of those alerts have high priority.
feat(Alerts.Repo): get by route ID + priority
This uses the helper function from the last commit to make it easy to fetch all alerts for a given route ID & priority.
refactor(DotcomWeb.ModeView): simpler has_alert?
Using the new
Alerts.Repofunction in place of the existing logic. We still have to narrow it down to the currently active ones.Since this changes the signature of
DotcomWeb.ModeView.has_alert?/3a bunch, I got to adjust a bunch of code calling it! As an aside... I have a near-term goal of having the homepage not need a huge list of all@alertsat all, and this'll help a lot 😃Note
I changed the underlying logic slightly -- the previous version used
Alerts.Alert.high_severity_or_high_priority?/1, which is actually inconsistent with the rest of the website.It also struck me as extraneous, as the logic which sets
priorityto:highalready incorporates high severity through this block...That was also the only place
Alerts.Alert.high_severity_or_high_priority?/1was invoked, so removing that call means I could delete that function too.Screenshots
No changes!
How to test
I extracted some flamegraphs... the middle section changed a lot 😅
Click to see them yourself
*note these flamegraphs omit the extra work done to render the alerts tab, because `FlameOn` kept timing outClick here to see Claude's interpretation of them
The big finding:
_grid_buttons.htmlwas spawning Tasks per renderIn the before flamegraph,
DotcomWeb.ModeViewrendering the grid buttons partial goes through this call chain:That's Task.async_stream (or similar) being used inside a template partial — spawning and supervising a separate BEAM process per grid button just to do (presumably) small, cheap work like resolving an icon or route link. In the after version, that entire code path is gone: the same partial now costs ~250µs total instead of tens of milliseconds per task. This alone accounts for roughly 58ms of the total 65ms improvement.
Overall numbers