Skip to content

Commit

Permalink
perf(ScheduleController): Only make requests async when more than 1
Browse files Browse the repository at this point in the history
  • Loading branch information
KaylaBrady committed Nov 7, 2024
1 parent 7015907 commit 43f4bb9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/mobile_app_backend_web/controllers/schedule_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ defmodule MobileAppBackendWeb.ScheduleController do

filters = Enum.map(stop_ids, &get_filter(&1, service_date))

data = case filters do
[filter] -> fetch_schedules(filter)
filters -> fetch_schedules_parallel(filters)
end
data =
case filters do
[filter] -> fetch_schedules(filter)
filters -> fetch_schedules_parallel(filters)
end

case data do
:error ->
Expand Down Expand Up @@ -93,12 +94,12 @@ defmodule MobileAppBackendWeb.ScheduleController do
%{schedules: [MBTAV3API.Schedule.t()], trips: JsonApi.Object.trip_map()}
| :error
defp fetch_schedules(filter) do
with {:ok, %{data: schedules, included: %{trips: trips}}} <-
Repository.schedules(filter: filter, include: :trip, sort: {:departure_time, :asc}) do
%{schedules: schedules, trips: trips}
else
_ -> :error
case Repository.schedules(filter: filter, include: :trip, sort: {:departure_time, :asc}) do
{:ok, %{data: schedules, included: %{trips: trips}}} ->
%{schedules: schedules, trips: trips}

_ ->
:error
end
end
end

0 comments on commit 43f4bb9

Please sign in to comment.