Skip to content

refactor & test homepage alerts - #3338

Merged
thecristen merged 3 commits into
mainfrom
cbj/homepage-alerts-refactor
Jul 16, 2026
Merged

thecristen merged 3 commits into
mainfrom
cbj/homepage-alerts-refactor

Conversation

@thecristen

Copy link
Copy Markdown
Collaborator

Scope

Asana Ticket: 📈 Speed up alerts call on the homepage

Implementation

Showing alerts on the homepage means we have to fetch all alerts, group them by applicable mode and accessibility effect, and fetch all the relating routes and stops so we could render the right route pills or stop links. When starting from an empty cache it's a lot of data fetching!

This PR does a couple things:

  1. The call to fetch all alerts was doing a little bit more than it needed to -- notably, Alerts.Repo.all/1 calls a function that calls Alerts.Sort.sort/1. For the homepage, we don't need any alert sorting - so I added a function that fetches all current alerts, without the sorting.
  2. Extracted the two data pipelines into two functions that I can add tests for. And rewrote them! The most impactful change there was probably using Task.async_stream/3 to manage fetching many routes or stops in parallel. Another improvement over the original code is that it doesn't break if the Routes.Repo and Stops.Repo calls return nil (which is a valid case).

How to test

I used Util.log_duration/3 to measure how long it takes to render the alerts tab HTML content given a list of alerts. All numbers are in ms

  • this branch, no cache - 883.581
  • this, everything cached - 3.682
  • main branch, no cache - 8338.736
  • main, everything cached - 6.147

@thecristen
thecristen requested a review from a team as a code owner July 15, 2026 14:34
@thecristen
thecristen requested a review from lvachon1 July 15, 2026 14:34
Comment thread lib/dotcom/alerts.ex
@thecristen
thecristen merged commit 18954f7 into main Jul 16, 2026
18 checks passed
@thecristen
thecristen deleted the cbj/homepage-alerts-refactor branch July 16, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants